import sys import hashlib # for a PRNG, SHA-1 is standard and sufficiently secure def hash(seed): h = hashlib.sha1(); h.update(seed); return h.digest() seedbytes = 20 # 160-bit size for seed, determined by SHA-1 output size def int2str(seed,bytes): # standard big-endian encoding of integer seed return ''.join([chr((seed//256^i)%256) for i in reversed(range(bytes))]) def str2int(seed): return Integer(seed.encode('hex'),16) def update(seed): # add 1 to seed, viewed as integer return int2str(str2int(seed) + 1,len(seed)) def real2str(seed,bytes): # most significant bits of real number between 0 and 1 return int2str(Integer(floor(RealField(8*bytes+8)(seed)*256^bytes)),bytes) sizes = [160,192,224,256,320,384,512] S = real2str(pi/16,len(sizes)*seedbytes) primeseeds = [S[i:i+seedbytes] for i in range(0,len(S),seedbytes)] S = real2str(exp(1)/16,len(sizes)*seedbytes) curveseeds = [S[i:i+seedbytes] for i in range(0,len(S),seedbytes)] for j in range(len(sizes)): L,S = sizes[j],primeseeds[j] v = (L-1)//160 def fullhash(seed,bits): h = hash(seed) for i in range(v): seed = update(seed); h += hash(seed) return str2int(h) % 2^bits while True: p = fullhash(S,L) while not (p % 4 == 3 and p.is_prime()): p += 1 if 2^(L-1) - 1 < p and p < 2^L: break S = update(S) k = GF(p) R. = k[] def secure(A,B): if k(B).is_square(): return False E = EllipticCurve([k(A),k(B)]) for q in [2,3,5,7]: # quick check whether q divides n, without computing n for r,e in E.division_polynomial(q).roots(): if E.is_x_coord(r): return False n = E.cardinality() return (n < p and n.is_prime() and Integers(n)(p).multiplicative_order() * 100 >= n-1) S = curveseeds[j] while True: A = fullhash(S,L-1) if not (k(A)*x^4+3).roots(): S = update(S); continue S = update(S) B = fullhash(S,L-1) if not secure(A,B): S = update(S); continue print 'p',hex(p).upper() print 'A',hex(A).upper() print 'B',hex(B).upper() sys.stdout.flush() break # output: # p E95E4A5F737059DC60DFC7AD95B3D8139515620F # A 2E2224B2759D5FB1A9E47C71EB7EACE045C0951 # B 15783031E0F7E2981E30C93C4E492B84112AA6B1 # p C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297 # A 7D15A709D0850E17FAFE6FF106576837A562EAD3F3154D56 # B 73154D56DC27DD3B8E7C08CA915B7922088066CDAEB33EEB # p D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF # A 2B98B906DC245F2916C03A2F953EA9AE565C3253E8AEC4BFE84C659E # B 68AEC4BFE84C659EBB8B81DC39355A2EBFA3870D98976FA2F17D2D8D # p A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377 # A 3EA36CD59B1ADD17AA85986A28EBF7D35F9D2393F2A1B36BB6F3F1C7606F6BF5 # B 72A1B36BB6F3F1C7606F6BF52B0F1F13B2B4405D73A75B6B0C8DB58D1440FF91 # p D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27 # A 76CF3AA77A4031979A3200E52728F918B77197F9189C35B46DB8208B1BE5635E6E97020882B5563E # B 189C35B46DB8208B1BE5635E6E97020882B5563EF95675555ECBCB9A9A0F9A8DA585E28C49DA70AB # p 8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53 # A 22D83655340DBDAA4FD1FB74953488B64D79B3AE60A61F0A9774EADE62DFFFA4B0FCD4EB5472D70C860103CE684A2DC8 # B 60A61F0A9774EADE62DFFFA4B0FCD4EB5472D70C860103CE684A2DC80C5EEECFF71CB65990FBFEE1E21276C05F7117D1 # p AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3 # A 7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA # B 3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723