Sum-O-Primes
This commit is contained in:
37
sum_o_primes/gen.py
Executable file
37
sum_o_primes/gen.py
Executable file
@@ -0,0 +1,37 @@
|
||||
#!python3
|
||||
|
||||
from binascii import hexlify
|
||||
from gmpy2 import mpz_urandomb, next_prime, random_state
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 9):
|
||||
import gmpy2
|
||||
math.gcd = gmpy2.gcd
|
||||
math.lcm = gmpy2.lcm
|
||||
|
||||
FLAG = open('flag.txt').read().strip()
|
||||
FLAG = int(hexlify(FLAG.encode()), 16)
|
||||
SEED = int(hexlify(os.urandom(32)).decode(), 16)
|
||||
STATE = random_state(SEED)
|
||||
|
||||
def get_prime(bits):
|
||||
return next_prime(mpz_urandomb(STATE, bits) | (1 << (bits - 1)))
|
||||
|
||||
p = get_prime(1024)
|
||||
q = get_prime(1024)
|
||||
|
||||
x = p + q
|
||||
n = p * q
|
||||
|
||||
e = 65537
|
||||
|
||||
m = math.lcm(p - 1, q - 1)
|
||||
d = pow(e, -1, m)
|
||||
|
||||
c = pow(FLAG, e, n)
|
||||
|
||||
print(f'x = {x:x}')
|
||||
print(f'n = {n:x}')
|
||||
print(f'c = {c:x}')
|
||||
Reference in New Issue
Block a user