Byte-Integer Encoding (bytes_to_long - long_to_bytes)
- •
What it is
- •
The convention of treating a byte string as one large big-endian base-256 integer — concatenate each byte's value and read the result as a single number (commonly shown in hex or decimal). This is how message bytes get turned into the integers that RSA, Diffie-Hellman, and other numeric cryptosystems actually operate on.
- •
- •
When to apply
- •
A challenge hands you a huge integer and expects text back, or vice versa — especially anything RSA-flavored, where plaintexts/ciphertexts are always integers under the hood.
- •
- •
Worked example
- •
"HELLO"→ ASCII bytes[72, 69, 76, 76, 79]→ hex0x48454c4c4f→ decimal310400273487.
- •
- •
Python
- •
from Crypto.Util.number import bytes_to_long, long_to_bytes n = bytes_to_long(b"HELLO") # 310400273487 b = long_to_bytes(n) # b'HELLO'
- •
- •
- •
Related
- •