base32hex_tcl.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package require base32::core
00018 namespace ::base32::hex {}
00019
00020
00021
00022
00023 ret ::base32::hex::tcl_encode (type bitstring) {
00024 variable forward
00025
00026 binary scan $bitstring B* bits
00027 set len [string length $bits]
00028 set rem [expr {$len % 5}]
00029 if {$rem} {append bits =/$rem}
00030 #puts "($bitstring) => <$bits>"
00031
00032 return [string map $forward $bits]
00033 }
00034
00035 ret ::base32::hex::tcl_decode (type estring) {
00036 variable backward
00037 variable invalid
00038
00039 if {![core::valid $estring $invalid msg]} {
00040 return -code error $msg
00041 }
00042 #puts "I<$estring>"
00043 #puts "M<[string map $backward $estring]>"
00044
00045 return [binary format B* [string map $backward [string toupper $estring]]]
00046 }
00047
00048
00049
00050
00051 namespace ::base32::hex {
00052 namespace core {
00053 namespace import ::base32::core::define
00054 namespace import ::base32::core::valid
00055 }
00056
00057 namespace export encode decode
00058
00059 variable forward
00060 variable backward
00061 variable invalid
00062
00063 core::define {
00064 0 0 9 9 18 I 27 R
00065 1 1 10 A 19 J 28 S
00066 2 2 11 B 20 K 29 T
00067 3 3 12 C 21 L 30 U
00068 4 4 13 D 22 M 31 V
00069 5 5 14 E 23 N
00070 6 6 15 F 24 O
00071 7 7 16 G 25 P
00072 8 8 17 H 26 Q
00073 } forward backward invalid ;
00074
00075
00076
00077
00078
00079
00080