Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.3 kB
5
Indexable
Never
import os
from math import prod
from Crypto.Util.number import isPrime, bytes_to_long
from Crypto.Cipher import AES
 
n_hex = "4eeb350ddc1320b06ec1956f225703ba4b087c35fe82a49310d1148ce6927fad89a1fe67ef95503c9555c10cb73136fead5c74719bf64e84fb1b7dd654c756ae4bd92b0664d06309cf90e432230954320470ae82a55d90259b3e961ad00bff672e0c8fceca2e9d3bc13006b34ec379d70a721f9ea8a5c995ad8593ee4406c8ccd38b06170a988135d655d5adfa048f7a83b9029ef26f6e09cfa87045d6a3a237402a48bd14d00c5273184e54cbb4234b2a2f1b606ba6c9ec2c962b2523f55256da617634c397f3356aa21915ebb045f8b0b9e100f750a87725c0cbdf0e2b15c689f54bf1b05ab5b226d1ec55786e8131264f7479d40caf4363df1e5fde93d22774685fb01e0007beb0ca3a0c8f78b0fc7bba7cef5b15f5a6f13fb25902d523e37ce27e5805b034343ae0f32f12bd73fb939fd4a508a4c9f62d49b3c1a4c6a9853579c089d56583031fa7efec5e52505dd23f505964a6df17b3a63e86c65dac4ab1abb41546ea115ac1b1d85c18963dab2e1946b18d7aeeb2f0147c220349daa156e213925dd04734c6edf9c3803979a9a548995a709fc1afd3e45116455160acbea579c02dabb74ce4c688554bdada0d89092527186427622ac4eb6e70192181343c086874abae37b6186ce455466218f9f2e65696b6dcd8323c8df244c08957811a0d9b0c37e6cfeb898462d433caec2ab6be9bc61a32eb3b5d95"
flag_hex = "00d992f89a24c20b9c8d77a760d7087f7d4cfa89254bf8ae3161f9267e7c0e1a53aa53658a162b5de305571d76c2f0da"
n_num = int(n_hex, 16)
flag_bytes = bytes.fromhex(flag_hex)
 
class PRNG:
    def __init__(self, seed):
        self.state = seed
        self.A = 2574075728169663774421561315431415276173294095797791071804714248410303618125
        self.B = 87736994699280841534870667657477253616147884454736852116822371260058821182713
        self.M = 2**256
 
    def getPrime(self):
        while True:
            self.state = (self.A * self.state + self.B) % self.M
            if isPrime(self.state):
                return self.state
 
# Solution: Random bytes are sorted and then the primes produced by them are multiplied together.
# We can brute force each prime, and if it divides N then it is very likely that this is a prime used
# to generate the key.
key = bytearray()
for i in range(0xff):
    prime = PRNG(i).getPrime()
    if(n_num % prime == 0):
        key.append(i)
 
 
cipher = AES.new(key, AES.MODE_ECB)
decrypted_flag = cipher.decrypt(flag_bytes)
print(decrypted_flag)
Leave a Comment