Base 10 and 16
Cryptography — Converting Text to a Number
Cryptosystems like RSA work with numbers, but our messages consist of characters (letters). To apply mathematical operations, messages need to be converted into numeric form.
The most common method is to take the ASCII bytes of the message, convert them to hexadecimal form, and then simply concatenate them in sequence. This resulting long hexadecimal value can also be treated as a base-16 number or a base-10 decimal number.
As an example:
xabar: HELLO ascii bayt: [72, 69, 76, 76, 79] hex bayt: [0x48, 0x45, 0x4c, 0x4c, 0x4f] base-16: 0x48454c4c4f base-10: 310400273487
Below is a large integer encoded using the same method. Convert it back to the original text message.
Given integer:
198974677777495821476335712892712909145306049542039928416716373344682544941090403019133
To do this in Python, you can use the PyCryptodome library. First, the module is imported via from Crypto.Util.number import *, and then using the long_to_bytes() function, the number is converted into a sequence of bytes (and from there into text).