ALL the CTFS of Crypto2025 finally

This commit is contained in:
emln
2025-06-02 19:35:30 +02:00
parent aa0fe54b3b
commit 50c18f35b9
442 changed files with 1743 additions and 8 deletions

View 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