We can represent our string in different formats, and with a number of characters to represent the binary values. In Base-2, we represent with [01] and have a binary format and in Base-32 we have [A-Z2-7=]. Base-64 is a common representation with [A-Za-z0-9+/=]. In this case we will try and detect the Base used, and decode the input string. A page for bases is [here].
Unbase |
Theory
If you are into cybersecurity you should hopefully know all about hexademical and Base64 format. With hex, we have a character set of [0–9A-F]. But, we also have many other Base character sets, such as Base58 for Bitcoin, and Base45 for the EU Green Passport.
>Base2
For “fred” we can represent our ASCII characters in a bit format, and where we have [here]:
01100110 01110010 01100101 01100100 f r e d
This is actually a Base-2 form.
Base16
It takes up too many characters for Base2, so we often group our bits into four, and then define the equivalent hex character. This then gives us:
0110 0110 0111 0010 0110 0101 0110 0100 6 6 7 2 6 5 6 4
The Base16 form of “help“ is thus “68656C70”. Here is an example of the conversion:
Figure 2: Conversion to hex
Base-64
Another common format is Base64, and which uses a character set of “[A-Za-z0–9+/=]”. With “help” we have:
01101000 01100101 01101100 01110000 h e l p 011010 000110 010101 101100 011100 00 Z n J l Z A = =
In this case we need the number of characters to be a multiple of four, so we pad the end of the Base16 string. This “fred” is “ZnJlZA==” in Base16 (hex). The Base64 mapping is:
Figure: Conversion to Base-64
Base58
Base58 is used in Bitcoin, we where have at the character set of: [1–9A-HJ-NP-Za-km-z]. This has been created to get rid of the characters that could be misinterpreted for a Bitcoin wallet address. These include ‘0’, ‘I’,’O’, and ’l’. An example is:
Input: fred Type: base58 Coding: 3ctAMq
Base45
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×256)+B=C+(D×45)+(E×45×45). For this we basically determine (A×256)+B and then divide by 45 and note the remainder. We then have a lookup table for the remainder values.
An example is [here]:
Input: test Type: base45 Coding: 7WE QE
Some character sets
Here are some character sets for a few others:
Base2 [01] Base3 [123] Base5 [01234] Base10 [0123456789] Base26 [A-Z] Base32 [A-Z2-7=] Base45 [0-9A-Z $%*+-./:] Base58 (bitcoin) [1-9A-HJ-NP-Za-km-z] Base62 [0-9A-Za-z] Base64 [A-Za-z0-9+/=] Base67 [A-Za-z0-9-.!~_] Base85 (Ascii85) [!"#$%&'()*+,-./0-9:;<=>?@A-Z[\]^_`a-u] Base91 [A-Za-z0-9!#$%&()*+,./:;<=>?@[]^_`{|}~"]
The full range is:
[*] Depth 1/1: base10 [*] Depth 1/1: base16 [*] Depth 1/1: base16-inv [*] Depth 1/1: base128 [*] Depth 1/2: base10 [*] Depth 1/2: base16 [*] Depth 2/2: base58-bitcoin [*] Depth 2/2: base58-flickr [*] Depth 2/2: base58-ripple [*] Depth 2/2: base62 [*] Depth 2/2: base63 [*] Depth 2/2: base64 [*] Depth 2/2: base67 [*] Depth 2/2: ascii85 [*] Depth 2/2: base85-adobe [*] Depth 2/2: base85-ipv6 [*] Depth 2/2: base85-xml [*] Depth 2/2: z85 [*] Depth 1/2: base16-inv [*] Depth 1/2: base128 [*] Depth 1/3: base10 [*] Depth 1/3: base16 [*] Depth 2/3: base58-bitcoin [*] Depth 3/3: base122 [*] Depth 2/3: base58-flickr [*] Depth 2/3: base58-ripple [*] Depth 3/3: base122 [*] Depth 2/3: base62 [*] Depth 3/3: base122 [*] Depth 2/3: base63 [*] Depth 2/3: base64 [*] Depth 2/3: base67 [*] Depth 3/3: base122 [*] Depth 2/3: ascii85 [*] Depth 2/3: base85-adobe [*] Depth 2/3: base85-ipv6 [*] Depth 2/3: base85-xml [*] Depth 2/3: z85 [*] Depth 3/3: base122 [*] Depth 1/3: base16-inv [*] Depth 1/3: base128 [*] Depth 1/4: base10 [*] Depth 1/4: base16 [*] Depth 2/4: base58-bitcoin [*] Depth 3/4: base122 [*] Depth 4/4: base122 [*] Depth 2/4: base58-flickr [*] Depth 2/4: base58-ripple [*] Depth 3/4: base122 [*] Depth 2/4: base62 [*] Depth 3/4: base122 [*] Depth 4/4: base122 [*] Depth 2/4: base63 [*] Depth 2/4: base64 [*] Depth 2/4: base67 [*] Depth 3/4: base122 [*] Depth 4/4: base122 [*] Depth 2/4: ascii85 [*] Depth 2/4: base85-adobe [*] Depth 2/4: base85-ipv6 [*] Depth 2/4: base85-xml [*] Depth 2/4: z85 [*] Depth 3/4: base122 [*] Depth 1/4: base16-inv [*] Depth 1/4: base128 [*] Depth 1/5: base10 [*] Depth 1/5: base16 [*] Depth 2/5: base58-bitcoin [*] Depth 3/5: base122 [*] Depth 4/5: base122 [*] Depth 5/5: base122 [*] Depth 2/5: base58-flickr [*] Depth 2/5: base58-ripple [*] Depth 3/5: base122 [*] Depth 2/5: base62 [*] Depth 3/5: base122 [*] Depth 4/5: base122 [*] Depth 5/5: base122 [*] Depth 2/5: base63 [*] Depth 2/5: base64 [*] Depth 2/5: base67 [*] Depth 3/5: base122 [*] Depth 4/5: base122 [*] Depth 2/5: ascii85 [*] Depth 2/5: base85-adobe [*] Depth 2/5: base85-ipv6 [*] Depth 2/5: base85-xml [*] Depth 2/5: z85 [*] Depth 3/5: base122 [*] Depth 1/5: base16-inv [*] Depth 1/5: base128 [*] Depth 1/6: base10 [*] Depth 1/6: base16 [*] Depth 2/6: base58-bitcoin [*] Depth 3/6: base122 [*] Depth 4/6: base122 [*] Depth 5/6: base122 [*] Depth 6/6: base122 [*] Depth 2/6: base58-flickr [*] Depth 2/6: base58-ripple [*] Depth 3/6: base122 [*] Depth 2/6: base62 [*] Depth 3/6: base122 [*] Depth 4/6: base122 [*] Depth 5/6: base122 [*] Depth 2/6: base63 [*] Depth 2/6: base64 [*] Depth 2/6: base67 [*] Depth 3/6: base122 [*] Depth 4/6: base122 [*] Depth 2/6: ascii85 [*] Depth 2/6: base85-adobe [*] Depth 2/6: base85-ipv6 [*] Depth 2/6: base85-xml [*] Depth 2/6: z85 [*] Depth 3/6: base122 [*] Depth 1/6: base16-inv [*] Depth 1/6: base128 [*] Depth 1/7: base10 [*] Depth 1/7: base16 [*] Depth 2/7: base58-bitcoin [*] Depth 3/7: base122 [*] Depth 4/7: base122 [*] Depth 5/7: base122 [*] Depth 6/7: base122 [*] Depth 2/7: base58-flickr [*] Depth 2/7: base58-ripple [*] Depth 3/7: base122 [*] Depth 2/7: base62 [*] Depth 3/7: base122 [*] Depth 4/7: base122 [*] Depth 5/7: base122 [*] Depth 2/7: base63 [*] Depth 2/7: base64 [*] Depth 2/7: base67 [*] Depth 3/7: base122 [*] Depth 4/7: base122 [*] Depth 2/7: ascii85 [*] Depth 2/7: base85-adobe [*] Depth 2/7: base85-ipv6 [*] Depth 2/7: base85-xml [*] Depth 2/7: z85 [*] Depth 3/7: base122 [*] Depth 1/7: base16-inv [*] Depth 1/7: base128 [*] Depth 1/8: base10 [*] Depth 1/8: base16 [*] Depth 2/8: base58-bitcoin [*] Depth 3/8: base122 [*] Depth 4/8: base122 [*] Depth 5/8: base122 [*] Depth 6/8: base122 [*] Depth 2/8: base58-flickr [*] Depth 2/8: base58-ripple [*] Depth 3/8: base122 [*] Depth 2/8: base62 [*] Depth 3/8: base122 [*] Depth 4/8: base122 [*] Depth 5/8: base122 [*] Depth 2/8: base63 [*] Depth 2/8: base64 [*] Depth 2/8: base67 [*] Depth 3/8: base122 [*] Depth 4/8: base122 [*] Depth 2/8: ascii85 [*] Depth 2/8: base85-adobe [*] Depth 2/8: base85-ipv6 [*] Depth 2/8: base85-xml [*] Depth 2/8: z85 [*] Depth 3/8: base122 [*] Depth 1/8: base16-inv [*] Depth 1/8: base128 [*] Depth 1/9: base10 [*] Depth 1/9: base16 [*] Depth 2/9: base58-bitcoin [*] Depth 3/9: base122 [*] Depth 4/9: base122 [*] Depth 5/9: base122 [*] Depth 6/9: base122 [*] Depth 2/9: base58-flickr [*] Depth 2/9: base58-ripple [*] Depth 3/9: base122 [*] Depth 2/9: base62 [*] Depth 3/9: base122 [*] Depth 4/9: base122 [*] Depth 5/9: base122 [*] Depth 2/9: base63 [*] Depth 2/9: base64 [*] Depth 2/9: base67 [*] Depth 3/9: base122 [*] Depth 4/9: base122 [*] Depth 2/9: ascii85 [*] Depth 2/9: base85-adobe [*] Depth 2/9: base85-ipv6 [*] Depth 2/9: base85-xml [*] Depth 2/9: z85 [*] Depth 3/9: base122 [*] Depth 1/9: base16-inv [*] Depth 1/9: base128 [*] Depth 01/10: base10 [*] Depth 01/10: base16 [*] Depth 02/10: base58-bitcoin [*] Depth 03/10: base122 [*] Depth 04/10: base122 [*] Depth 05/10: base122 [*] Depth 06/10: base122 [*] Depth 02/10: base58-flickr [*] Depth 02/10: base58-ripple [*] Depth 03/10: base122 [*] Depth 02/10: base62 [*] Depth 03/10: base122 [*] Depth 04/10: base122 [*] Depth 05/10: base122 [*] Depth 02/10: base63 [*] Depth 02/10: base64 [*] Depth 02/10: base67 [*] Depth 03/10: base122 [*] Depth 04/10: base122 [*] Depth 02/10: ascii85 [*] Depth 02/10: base85-adobe [*] Depth 02/10: base85-ipv6 [*] Depth 02/10: base85-xml [*] Depth 02/10: z85 [*] Depth 03/10: base122 [*] Depth 01/10: base16-inv [*] Depth 01/10: base128 fred