Integers to octet strings (I2OSP)

Tim Churches tchur at
Wed Jul 14 10:27:55 CEST 2004

What is the most efficient method in Python for converting positive
integers (including long integers) to octet strings, as per the common
cryptographic data conversion conversion I2OSP (formal definition can be
found here: )? I thought of converting
the integer to hex with hex() and then converting pairs of the resulting
hex characters into bytes using int() and then chr(), but this seems a
bit clunky. Googling for 30 minutes didn't turn up any example code in
Python (or much else).

Tim C

PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere
or at
Key fingerprint = 8C22 BF76 33BA B3B5 1D5B  EB37 7891 46A9 EAF9 93D0

More information about the Python-list mailing list