I am having trouble decoding a number back into its character form. Each letter encoded using a base string of 96 letters
Example: To code "DCODE", written in base 26, ABCDEFGHIJKLMNOPQRSTUVWXYZ, convert it to base 10:
D=3, C=2, O=14, D=3, E=4 so
(3 x 26^4) + (2x26^2) + (14 x 26^1) + (4x 26^0) = 1415626
I understand how to encode it, but I'm confused on how we would go about decoding it? My base is 96 and not 26 but it's similar logic and I just found the above example online. We are given the size of the string, block_size
, and the total amount, num
.
alpha = """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
if num < len(alpha):
letter = alpha[num]
text = ("a"*(block_size-1)) + letter
So far my cases only cover ones less than 96.: Similar to this except different bases: https://www.dcode.fr/base-26-cipher