
Member-only story
So What Is Base-45, And Where Is It Used?
If you are into Cybersecurity, Base-64 should be a well-known format, and often used to convert binary data into a text format. In Bitcoin, we use Base-58 for the Bitcoin address. But, what is Base-45?
Well, your vaccine status document probably contains a QR code, and which uses Base-45 format for the data coding [article]. With Base-45 format, we have 45 characters defined. The encoding table is [here]:
Value Encoding Value Encoding Value Encoding Value Encoding
00 0 12 C 24 O 36 Space
01 1 13 D 25 P 37 $
02 2 14 E 26 Q 38 %
03 3 15 F 27 R 39 *
04 4 16 G 28 S 40 +
05 5 17 H 29 T 41 -
06 6 18 I 30 U 42 .
07 7 19 J 31 V 43 /
08 8 20 K 32 W 44 :
09 9 21 L 33 X
10 A 22 M 34 Y
11 B 23 N 35 Z
With this we take the data stream with two bytes [A, B] at a time, and and convert into [ C, D, E] and where:
(A*256) + B = C + (D*45) + (E*45*45).
For example, for “hello”, we have:
h e l l o
0110 1000 0110 0101 0110 1100 0110 1100 0110 1111
The first two bytes are A=64+32+8=104 and B=64+32+5 =101, and where:
(104*256)+101 = 26,725
We then divide by 45 and note the remainder:
26725 / 45 = 593 r 40 = ‘+’
593 /45 = 13 r 8 -> ‘8’
13/45 = 0 r 13 -> ‘D’
Thus “he” maps to “+8D” in Base-45. A full example is (note that there is a space in the encoded string) [here]:
h e l l o
0110 1000 0110 0101 0110 1100 0110 1100 0110 1111Message: hello 68656c6c6f
Encoded: +8D VDL2
Decode: hello
The code is [here]:
import base45
import sysmessage="hello"
if (len(sys.argv)>1):
message=str(sys.argv[1])en = base45.b45encode(message.encode())print ("Message:\t",message,message.encode().hex())
print ("Encoded:\t",en.decode())de = base45.b45decode(en)
print ("Decode:\t\t",de.decode())
Subscribe: https://billatnapier.medium.com/membership