b64.tcl (1964B)
1 proc b64e {numb} { 2 set b64 [split "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\[\]" {}] 3 4 set res "" 5 while {$numb != 0} { 6 append res [lindex $b64 [expr {$numb % 64}]] 7 set numb [expr {$numb>>6}] 8 } 9 if {[string length $res] == 0} { 10 set res "A" 11 } 12 return [string reverse $res] 13 } 14 15 proc b64d {numb} { 16 set b64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\[\]" 17 set numb [string trimleft $numb "A"] 18 set res 0 19 for {set i 0} {$i<[string length $numb]} {incr i} { 20 set new [string first [string index $numb $i] $b64] 21 incr res [expr {$new<<(6*$i)}] 22 } 23 return $res 24 } 25 26 namespace eval unreal { 27 proc ::unreal::b64e {numb} { 28 set b64 [split "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}" {}] 29 30 set res "" 31 while {$numb != 0} { 32 append res [lindex $b64 [expr {$numb % 64}]] 33 set numb [expr {$numb>>6}] 34 } 35 if {[string length $res] == 0} { 36 set res "A" 37 } 38 return [string reverse $res] 39 } 40 41 proc ::unreal::b64d {numb} { 42 set b64 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}" 43 set numb [string trimleft $numb "A"] 44 set res 0 45 for {set i 0} {$i<[string length $numb]} {incr i} { 46 set new [string first [string index $numb $i] $b64] 47 incr res [expr {$new<<(6*$i)}] 48 } 49 return $res 50 } 51 } 52 53 namespace eval ts6 { 54 proc ::ts6::b64e {numb} { 55 set b64 [split "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" {}] 56 57 set res "" 58 while {$numb != 0} { 59 append res [lindex $b64 [expr {$numb % 36}]] 60 set numb [expr {$numb / 36}] 61 } 62 if {[string length $res] == 0} { 63 set res "A" 64 } 65 return [string reverse $res] 66 } 67 68 proc ::ts6::b64d {numb} { 69 set b64 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 70 set numb [string trimleft $numb "A"] 71 set res 0 72 for {set i 0} {$i<[string length $numb]} {incr i} { 73 set new [string first [string index $numb $i] $b64] 74 incr res [expr {$new * (36 * $i)+1}] 75 } 76 return $res 77 } 78 }