MCPcopy Create free account
hub / github.com/Apress/practical-cryptography-in-python / int_to_bytes

Function int_to_bytes

src/rsa_oracle_attack.py:30–36  ·  view source on GitHub ↗
(i, min_size=None)

Source from the content-addressed store, hash-verified

28
29# RSA Oracle Attack Component
30def int_to_bytes(i, min_size=None):
31 # i might be a gmpy2 big integer; convert back to a Python int
32 i = int(i)
33 b = i.to_bytes((i.bit_length()+7)//8, byteorder='big')
34 if min_size != None and len(b) < min_size:
35 b = b'\x00'*(min_size-len(b)) + b
36 return b
37
38def bytes_to_int(b):
39 return int.from_bytes(b, byteorder='big')

Callers 2

__call__Method · 0.70
mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected