from sympy import randprime, nextprime, isprime
import os, math
x = b"\x80\x00\x00\x00\x00\x00\x00\x01"
j = 0
while True:
j += 1
p = randprime(0, (1 << 256))
l = int.from_bytes(x + os.urandom(56), "big")
q = l // p # nextprime(l // p);
if isprime(q):
break
n = q * p;
print(str(l.bit_length()) + ":" + hex(l >> 256) + "...")
print(str(n.bit_length()) + ":" + hex(n >> 256) + "...")
print(str(p.bit_length()) + ":" + hex(p))
print(str(q.bit_length()) + ":" + hex(q))
# check key, textbook RSA
f = (p - 1) * (q - 1)
e = 65537
d = pow(e, -1, f)
m = 0xDEADBEEFCAFEBABE
c = pow(m, e, n)
t = pow(c, d, n)
#находки