com_projet/challenge.py

58 lines
2.8 KiB
Python
Raw Normal View History

2026-11-05 11:27:37 +01:00
from intro import (
int_to_ascii,
hex_to_ascii,
hex_to_b64,
int_to_message_rsa,
xor_13,
unxor_flag,
mystery_xor,
mystery_key,
2026-11-05 11:27:37 +01:00
)
from modular_arithmetic import (
gcd,
)
from public_key_cryptography import (
modular_exponentiation,
basic_encryption,
Euler_totient,
private_key,
decode,
hash_and_encrypt,
prime_factorization,
reverse_single_prime_RSA_cipher,
)
2026-11-05 11:10:32 +01:00
if __name__ == "__main__":
# fmt: off
# Intro-level challenges
2026-11-05 11:10:32 +01:00
print(int_to_ascii([99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125]))
print(hex_to_ascii("63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d"))
print(hex_to_b64("72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf"))
print(int_to_message_rsa(11515195063862318899931685488813747395775516287289682636499965282714637259206269))
2026-11-05 11:19:40 +01:00
print("crypto{{{}}}".format(xor_13("label")))
2026-11-05 11:27:37 +01:00
print(unxor_flag(0xa6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313,
0x37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e,
0xc1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1,
0x04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf
))
print(mystery_xor(0x73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d))
print(mystery_key(0x0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104))
# Public-key cryptography course challenges
print(modular_exponentiation())
print(basic_encryption(12, 17, 23))
print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219))
print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001))
print(decode(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001, 77578995801157823671636298847186723593814843845525223303932))
print(hash_and_encrypt("crypto{Immut4ble_m3ssag1ng}"))
# print(prime_factorization(510143758735509025530880200653196460532653147)) # too slow
print(reverse_single_prime_RSA_cipher(
161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942,
171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591,
65537
))
# Modular arithmetic course challenge
print(gcd(66528, 52920))
# fmt: on