ALL the CTFS of Crypto2025 finally
This commit is contained in:
31
crypto-asimmetric/inferious_prime/challenge.py
Normal file
31
crypto-asimmetric/inferious_prime/challenge.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from Cryptodome.Util.number import getPrime, inverse, bytes_to_long, long_to_bytes, GCD
|
||||
from secret import flag
|
||||
|
||||
assert len(flag) == 23
|
||||
|
||||
e = 3
|
||||
|
||||
# n will be 8 * (100 + 100) = 1600 bits strong which is pretty good
|
||||
while True:
|
||||
#getPrime is 100 bits not 100 Bytes
|
||||
p = getPrime(100)
|
||||
q = getPrime(100)
|
||||
phi = (p - 1) * (q - 1)
|
||||
d = inverse(e, phi)
|
||||
if d != -1 and GCD(e, phi) == 1:
|
||||
break
|
||||
|
||||
n = p * q
|
||||
|
||||
pt = bytes_to_long(flag)
|
||||
ct = pow(pt, e, n)
|
||||
|
||||
print(f"n = {n}")
|
||||
print(f"e = {e}")
|
||||
print(f"ct = {ct}")
|
||||
|
||||
pt = pow(ct, d, n)
|
||||
decrypted = long_to_bytes(pt)
|
||||
assert decrypted == flag
|
||||
Reference in New Issue
Block a user