Base45Base45 format is used in applications such as QR codes within vaccination passports. With this we take two bytes are a time [A, B] and then determine the values of [C, D and E] for: \((A \times 256) + B = C + (D \times 45) + (E \times 45 \times 45)\). For this we basically determine \((A \times 256)+B\) and then divide by 45 and note the remainder. We then have a lookup table for the remainder values. |
Outline
Base45 format is used in applications such as QR codes within vaccination passports. With this we take two bytes are a time [A, B] and then determine the values of [C, D and E] for: \((A \times 256) + B = C + (D \times 45) + (E \times 45 \times 45)\). For this we basically determine \((A \times 256) + B\) and then divide by 45 and note the remainder. We then have a lookup table for the remainder values. The table for the conversion is:
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
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 we get:
(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’
The result is:
h e l l o 0110 1000 0110 0101 0110 1100 0110 1100 0110 1111 Encoded: +8D VDL2 Decode: hello
The following gives some Python code:
import base45 import sys message="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())
A sample run:
Message: hello 68656c6c6f Encoded: +8D VDL2 Decode: hello