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,
|
2026-11-05 11:30:43 +01:00
|
|
|
mystery_xor,
|
2026-11-05 11:52:31 +01:00
|
|
|
mystery_key,
|
2026-11-05 11:27:37 +01:00
|
|
|
)
|
2026-11-14 14:21:05 +01:00
|
|
|
from modular_arithmetic import (
|
|
|
|
|
gcd,
|
2026-11-14 14:31:38 +01:00
|
|
|
extended_gcd,
|
2026-11-14 14:46:20 +01:00
|
|
|
quadratic_residue,
|
2026-11-14 23:31:37 +01:00
|
|
|
legendre_symbol,
|
2026-11-14 23:34:50 +01:00
|
|
|
tonelli_shanks,
|
2026-11-14 14:21:05 +01:00
|
|
|
)
|
2026-11-05 12:08:15 +01:00
|
|
|
from public_key_cryptography import (
|
|
|
|
|
modular_exponentiation,
|
|
|
|
|
basic_encryption,
|
2026-11-05 12:09:50 +01:00
|
|
|
Euler_totient,
|
2026-11-05 12:12:37 +01:00
|
|
|
private_key,
|
2026-11-05 13:06:33 +01:00
|
|
|
decode,
|
2026-11-14 12:41:40 +01:00
|
|
|
hash_and_encrypt,
|
2026-11-14 13:02:10 +01:00
|
|
|
prime_factorization,
|
2026-11-14 13:24:19 +01:00
|
|
|
reverse_single_prime_RSA_cipher,
|
2026-11-05 12:08:15 +01:00
|
|
|
)
|
2026-11-14 14:46:20 +01:00
|
|
|
import functools
|
2026-11-05 11:10:32 +01:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# fmt: off
|
2026-11-14 14:21:05 +01:00
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
))
|
2026-11-05 11:30:43 +01:00
|
|
|
print(mystery_xor(0x73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d))
|
2026-11-05 11:52:31 +01:00
|
|
|
print(mystery_key(0x0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104))
|
2026-11-14 14:21:05 +01:00
|
|
|
|
2026-11-05 12:08:15 +01:00
|
|
|
# Public-key cryptography course challenges
|
|
|
|
|
print(modular_exponentiation())
|
|
|
|
|
print(basic_encryption(12, 17, 23))
|
2026-11-05 12:09:50 +01:00
|
|
|
print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219))
|
2026-11-05 12:12:37 +01:00
|
|
|
print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001))
|
2026-11-05 13:06:33 +01:00
|
|
|
print(decode(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001, 77578995801157823671636298847186723593814843845525223303932))
|
2026-11-14 12:41:40 +01:00
|
|
|
print(hash_and_encrypt("crypto{Immut4ble_m3ssag1ng}"))
|
2026-11-14 13:24:19 +01:00
|
|
|
# print(prime_factorization(510143758735509025530880200653196460532653147)) # too slow
|
|
|
|
|
print(reverse_single_prime_RSA_cipher(
|
|
|
|
|
161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942,
|
|
|
|
|
171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591,
|
|
|
|
|
65537
|
|
|
|
|
))
|
2026-11-14 14:21:05 +01:00
|
|
|
|
|
|
|
|
# Modular arithmetic course challenge
|
|
|
|
|
print(gcd(66528, 52920))
|
2026-11-14 14:31:38 +01:00
|
|
|
print(extended_gcd(26513, 32321))
|
2026-11-14 14:34:57 +01:00
|
|
|
print(f"11 % 6 = {11 % 6}; 8146798528947 % 17 = {8146798528947 % 17}")
|
2026-11-14 14:46:20 +01:00
|
|
|
print(min([(quadratic_residue(29, x) or 30) for x in [14, 6, 11]])) # Bancal mais on est mod29 donc 30 est forcément pas le min.
|
2026-11-14 23:31:37 +01:00
|
|
|
print(
|
|
|
|
|
legendre_symbol(
|
|
|
|
|
101524035174539890485408575671085261788758965189060164484385690801466167356667036677932998889725476582421738788500738738503134356158197247473850273565349249573867251280253564698939768700489401960767007716413932851838937641880157263936985954881657889497583485535527613578457628399173971810541670838543309159139,
|
|
|
|
|
[
|
|
|
|
|
25081841204695904475894082974192007718642931811040324543182130088804239047149283334700530600468528298920930150221871666297194395061462592781551275161695411167049544771049769000895119729307495913024360169904315078028798025169985966732789207320203861858234048872508633514498384390497048416012928086480326832803,
|
|
|
|
|
45471765180330439060504647480621449634904192839383897212809808339619841633826534856109999027962620381874878086991125854247108359699799913776917227058286090426484548349388138935504299609200377899052716663351188664096302672712078508601311725863678223874157861163196340391008634419348573975841578359355931590555,
|
|
|
|
|
17364140182001694956465593533200623738590196990236340894554145562517924989208719245429557645254953527658049246737589538280332010533027062477684237933221198639948938784244510469138826808187365678322547992099715229218615475923754896960363138890331502811292427146595752813297603265829581292183917027983351121325,
|
|
|
|
|
14388109104985808487337749876058284426747816961971581447380608277949200244660381570568531129775053684256071819837294436069133592772543582735985855506250660938574234958754211349215293281645205354069970790155237033436065434572020652955666855773232074749487007626050323967496732359278657193580493324467258802863,
|
|
|
|
|
4379499308310772821004090447650785095356643590411706358119239166662089428685562719233435615196994728767593223519226235062647670077854687031681041462632566890129595506430188602238753450337691441293042716909901692570971955078924699306873191983953501093343423248482960643055943413031768521782634679536276233318,
|
|
|
|
|
85256449776780591202928235662805033201684571648990042997557084658000067050672130152734911919581661523957075992761662315262685030115255938352540032297113615687815976039390537716707854569980516690246592112936796917504034711418465442893323439490171095447109457355598873230115172636184525449905022174536414781771,
|
|
|
|
|
50576597458517451578431293746926099486388286246142012476814190030935689430726042810458344828563913001012415702876199708216875020997112089693759638454900092580746638631062117961876611545851157613835724635005253792316142379239047654392970415343694657580353333217547079551304961116837545648785312490665576832987,
|
|
|
|
|
96868738830341112368094632337476840272563704408573054404213766500407517251810212494515862176356916912627172280446141202661640191237336568731069327906100896178776245311689857997012187599140875912026589672629935267844696976980890380730867520071059572350667913710344648377601017758188404474812654737363275994871,
|
|
|
|
|
4881261656846638800623549662943393234361061827128610120046315649707078244180313661063004390750821317096754282796876479695558644108492317407662131441224257537276274962372021273583478509416358764706098471849536036184924640593888902859441388472856822541452041181244337124767666161645827145408781917658423571721,
|
|
|
|
|
18237936726367556664171427575475596460727369368246286138804284742124256700367133250078608537129877968287885457417957868580553371999414227484737603688992620953200143688061024092623556471053006464123205133894607923801371986027458274343737860395496260538663183193877539815179246700525865152165600985105257601565,
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
) # Bancal mais on est mod beaucoup donc -1 est forcément pas le max.
|
2026-11-14 23:34:50 +01:00
|
|
|
print(tonelli_shanks(8479994658316772151941616510097127087554541274812435112009425778595495359700244470400642403747058566807127814165396640215844192327900454116257979487432016769329970767046735091249898678088061634796559556704959846424131820416048436501387617211770124292793308079214153179977624440438616958575058361193975686620046439877308339989295604537867493683872778843921771307305602776398786978353866231661453376056771972069776398999013769588936194859344941268223184197231368887060609212875507518936172060702209557124430477137421847130682601666968691651447236917018634902407704797328509461854842432015009878011354022108661461024768, 30531851861994333252675935111487950694414332763909083514133769861350960895076504687261369815735742549428789138300843082086550059082835141454526618160634109969195486322015775943030060449557090064811940139431735209185996454739163555910726493597222646855506445602953689527405362207926990442391705014604777038685880527537489845359101552442292804398472642356609304810680731556542002301547846635101455995732584071355903010856718680732337369128498655255277003643669031694516851390505923416710601212618443109844041514942401969629158975457079026906304328749039997262960301209158175920051890620947063936347307238412281568760161))
|
2026-11-05 12:08:15 +01:00
|
|
|
# fmt: on
|