1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| from Crypto.Util.number import getPrime, bytes_to_long import math
FLAG = 'TUTCTF{???}' victory_key = "TUTCTF"
def victory_encrypt(plaintext, key): key = key.upper() key_length = len(key) plaintext = plaintext.upper() ciphertext = ''
for i, char in enumerate(plaintext): if char.isalpha(): shift = ord(key[i % key_length]) - ord('A') encrypted_char = chr((ord(char) - ord('A') + shift) % 26 + ord('A')) ciphertext += encrypted_char else: ciphertext += char
return ciphertext
def generate_parameters(bit_length=512): p = getPrime(bit_length) q = getPrime(bit_length) n = p * q e = 65537 phi = (p - 1) * (q - 1) d = pow(e, -1, phi) s = p ** 4 + q ** 4 return n, e, d, s, p, q
def main(): n, e, d, s, p, q = generate_parameters() flag = victory_encrypt(FLAG, victory_key).encode() c = pow(bytes_to_long(flag), e, n)
with open('output.txt', 'w') as f: f.write(f"n = {n}\n") f.write(f"e = {e}\n") f.write(f"c = {c}\n") f.write(f"s = {s}\n")
print("[+] Parameters saved to output.txt")
if __name__ == "__main__": main()
|