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