base32 Algorithm
The base32 algorithm is a widely adopted encoding scheme that is used to represent binary data in an ASCII string format by translating it into a radix-32 representation. It is a more compact version of the Base64 encoding scheme and is primarily designed for use in situations where space constraints or case insensitivity are of particular concern. The algorithm uses a set of 32 alphanumeric characters, specifically the uppercase letters A to Z and the digits 2 to 7. Each character in the base32 alphabet represents exactly 5 bits of data, which means that the base32 encoded string will be approximately 20% larger than the original binary data.
To encode data using the base32 algorithm, the input binary data is first divided into 5-bit groups. If the total number of bits is not a multiple of 5, additional padding bits are added to the last group to make it a complete 5-bit group. Each 5-bit group is then mapped to its corresponding character in the base32 alphabet. If padding bits were added earlier, they are represented by the '=' character at the end of the encoded string. The resulting string can be easily transmitted or stored in systems that are not sensitive to case or where space is a premium. To decode the base32 encoded data, the process is simply reversed - each character in the encoded string is mapped back to its corresponding 5-bit group, and the padding bits, if present, are removed to obtain the original binary data.
import base64
def main():
inp = input("->")
encoded = inp.encode("utf-8") # encoded the input (we need a bytes like object)
b32encoded = base64.b32encode(encoded) # b32encoded the encoded string
print(b32encoded)
print(base64.b32decode(b32encoded).decode("utf-8")) # decoded it
if __name__ == "__main__":
main()