CryptoHack

Note : A JOURNEY TO GAIN KNOWLEDGE

General

#XOR Properties

import binascii
def byte_xor(ba1, ba2):
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])
s1 = "a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313"
s2 = "37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e"
s3 = "c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1"
s4 = "04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf"
s2 = bytes.fromhex(s2)
s3 = bytes.fromhex(s3)
s4 = bytes.fromhex(s4)
key1 = bytes.fromhex(s1)
key2 = b'\x91\x14\x04\xe1?\x94\x88N\xab\xbe\xc9%\x85\x12@\xa5/\xa3\x81\xdd\xb7\x97\x00\xddm\r'
key13 = b'\xf6\x88\xe5\xc4kq\xdf\xe3\x0b]F\x0b\xd7\xe3f@m\xe33\x8a\xdb\x14\xc4\xc4\x01\xdf'
k = b'g\x9c\xe1%T\xe5W\xad\xa0\xe3\x8f.R\xf1&\xe5B@\xb2Wl\x83\xc4\x19l\xd2'
a_list = byte_xor(k,s4)

print(a_list)

The special thing of XOR operator is when you xor with same key you can get the original message .

a ^ b = c => a = b ^ c

(encrypt = message ^ key => message = encrypt ^ key)

crypto{x0r_i5_ass0c1at1v3}

#Favourite byte

s1 = "73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d"
s1 = bytes.fromhex(s1)

def single_byte_xor(b, key) -> bytes:
    """Given a plain text `text` as bytes and an encryption key `key` as a byte
    in range [0, 256) the function encrypts the text by performing
    XOR of all the bytes and the `key` and returns the resultant.
    """
    return bytes([b ^ key for b in s1])
for c in range(256):
	if b'crypto' in single_byte_xor(s1, c):
		print(single_byte_xor(s1,c))

key word "a single byte" . Xor each character with integer in range [0,256).

crypto{0x10_15_my_f4v0ur173_by7e}

You either know, XOR you don't

encrypt = "0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104"
encrypt = bytes.fromhex(encrypt)
key_form = b'crypto{'

key = [s1 ^ s2 for (s1, s2) in zip(encrypt, key_form)] + [ord("y")]


flag = []
for i in range(len(encrypt)):
    flag.append(encrypt[i] ^ key[i%len(key)])
for c in flag:
    print(chr(c), end ="")

Idea: Find key by xor encrypt message and key_form then xor key with encrypt.

crypto{1f_y0u_Kn0w_En0uGH_y0u_Kn0w_1t_4ll}

#Lemur XOR

What do you think about Adobe?

Adobe Photoshop why not ? :>

crypto{X0Rly_n0t ? }

#Break RSA

Tonelli–Shanks algorithm

def legendre(a, p):
    return pow(a, (p - 1) // 2, p)
 
def tonelli(n, p):
    assert legendre(n, p) == 1, "not a square (mod p)"
    q = p - 1
    s = 0
    while q % 2 == 0:
        q //= 2
        s += 1
    if s == 1:
        return pow(n, (p + 1) // 4, p)
    for z in range(2, p):
        if p - 1 == legendre(z, p):
            break
    c = pow(z, q, p)
    r = pow(n, (q + 1) // 2, p)
    t = pow(n, q, p)
    m = s
    t2 = 0
    while (t - 1) % p != 0:
        t2 = (t * t) % p
        for i in range(1, m):
            if (t2 - 1) % p == 0:
                break
            t2 = (t2 * t2) % p
        b = pow(c, 1 << (m - i - 1), p)
        r = (r * b) % p
        c = (b * b) % p
        t = (t * c) % p
        m = i
    return r
 
p=27772857409875257529415990911214211975844307184430241451899407838750503024323367895540981606586709985980003435082116995888017731426634845808624796292507989171497629109450825818587383112280639037484593490692935998202437639626747133650990603333094513531505209954273004473567193235535061942991750932725808679249964667090723480397916715320876867803719301313440005075056481203859010490836599717523664197112053206745235908610484907715210436413015546671034478367679465233737115549451849810421017181842615880836253875862101545582922437858358265964489786463923280312860843031914516061327752183283528015684588796400861331354873


n = 20058442271887390782341184553061693259218418956749367788824628331872951745693512666971057383133087145112672251544375693720903210309282292454435797503703963084282995922799267630989319592605415992771069804154505046471899368694387498398677671153177173001176232341893700315420538967289845800479312887797111470649358418178557722902634481957860132330775228811481649888112684228430126737629529135768061434048677678809834480772389209710436916268063442944861678775938178803409222396101086687028222333979529287399821437653336368165308841484432081379655209496176144360301915193174027514866451178023988032198572385093175849110662
c2 = 7714415137987866747074806358152518716625888227680873663074779506877551278629855228569924223453622840867331183537741302167114521117352553354188998788804026087214633186651558187598063519675223044713523686538430951730538270932359635252312932179917340530328977612379304158146654268245216142512438044928697208600606248912165757495282233363016735472944072501958355186943796975428883753207070581755602763063375527935401427838095698004773520144952103726172799591741286430327893153350763123392794847863086593436432438208765177417613596373926184584834576967747135952558927838740488546461301005259539983486016411307685482244211
c3=17098975897428456716194270927415356864954096642606493929059154866703557888462954947912008872552339352205990175483498505792117985904083699289681502671418679914191897758540195962573914609283592038873720221085036155580437338159458620150444238622368726779473079552388042681202096679228679076368554549055661796394456104095267187679182253465150159379287281763735900063005517584310979842781524143711194375107870488731830983791884591706011715389067506588660474121594503391263616188085308206323734799724188169301886601066541034602498625207501106826469220173374966851129503005821026262779184367623692057319176056166273701255937
c4=10673881512446800813221719983798855110890210541823747522840252972046945135860412947628972734034370633774013259598618490095899745522551146518943293621089309257305731350910629856013468502997046998610873269607899842622000301467288513500546364710725786752032130401884961792365096556306382866623196383670146882855508562995456292718734461855726708424432019549704105012050963619548030648055075573812469822004182718013404924818600316009198721023948040082374004246084961842473499361366541604097282382118427711534367274795560510980423812650857159138020566290548313461731340026093489798548567815659835958365412740234587630098936
c5 = 5370880177111772214966546989780441184730582979088758194198682681008863224482634838132300999325647948020669097872225930157677364880187170876526265706842694194817578106909197243970588941339921130887677710793075528335843046264994387999241539379961528661362926489572004938607247080065754774399781057421287427370041922231774646799000471046519617269175802256452115093380121098704284238963938166801256148574846004557731299841068446848016662269146335836458809411833017994122500323517829063121087409567809485321633279599141185122092531690838114539687787203275626675170771604097842940338370255078417038830200297871843596952086
c6 = 22401977232763485314449443921433770791113724205341483257700725157741639799840733057408680607261062037959334337209891065730340366546447674932098530585665294976680051002541628574616794170940717906596915779899860469866594593361752745651749063953132984870142283464700999534959946155469307168591969875304521251879922744858948833598916244274357250534543499056987889981676360105154726251872661550722408048537207202187504608769416460867193774143869210834575668955846447239614615225934020747299929772274806395514620596262960360460829906167520151424801999260647653637690071427816673120989381928205110976854388498529017734402787
c7 = 17974135028758639473188353434648645491825700931236018696547434635242040282069845584386905412452009840704475856476581174106472693238791276610118802768100701650527558338278546414415378899970206537237127882220830766500528027003674789767048386526159609001904570277574656234140949464048540410769681523114293950493903769460786635702910341667700875169045622674106994566211435218251682119656243455063173803794055498145478551555098536906666404957084392548680931128001248227132422925984458961111491476389573158695174961045341543301293114303398775480666447753713570047722665700557422845178760475114203326996035949766196813800137
c8 = 9798722381116618056227637476565566484018606253194222755351973203508462742253522311154076194134700145275527578605535821781545038187843569198505993524407287520970070771172279404172004212310432500247465608472105231701909612623072343883942216806934904529600639676698348239426243771486521532222069409611514728756060897629936844695006373653175992634673678639333010508845045985607328371180356262460490393317997708599757357055386370808544031455931154122353547239678217006604692623467390849309525705453042722141078914816760002281629323554959490483823338710209710265138177331357093216148991708169324688688552846634664517554736


r = tonelli(n, p)


assert (r * r - n) % p == 0
print("n = %d p = %d" % (n, p))
print("\t  roots : %d %d" % (r, p - r))
print(hex(r), hex(p-r))

Adrien's Signs

from random import randint

a = 288260533169915
p = 1007621497415251

FLAG = b'crypto{????????????????????}'

ciphertext = [67594220461269, 501237540280788, 718316769824518, 296304224247167, 48290626940198, 30829701196032, 521453693392074, 840985324383794, 770420008897119, 745131486581197, 729163531979577, 334563813238599, 289746215495432, 538664937794468, 894085795317163, 983410189487558, 863330928724430, 996272871140947, 352175210511707, 306237700811584, 631393408838583, 589243747914057, 538776819034934, 365364592128161, 454970171810424, 986711310037393, 657756453404881, 388329936724352, 90991447679370, 714742162831112, 62293519842555, 653941126489711, 448552658212336, 970169071154259, 339472870407614, 406225588145372, 205721593331090, 926225022409823, 904451547059845, 789074084078342, 886420071481685, 796827329208633, 433047156347276, 21271315846750, 719248860593631, 534059295222748, 879864647580512, 918055794962142, 635545050939893, 319549343320339, 93008646178282, 926080110625306, 385476640825005, 483740420173050, 866208659796189, 883359067574584, 913405110264883, 898864873510337, 208598541987988, 23412800024088, 911541450703474, 57446699305445, 513296484586451, 180356843554043, 756391301483653, 823695939808936, 452898981558365, 383286682802447, 381394258915860, 385482809649632, 357950424436020, 212891024562585, 906036654538589, 706766032862393, 500658491083279, 134746243085697, 240386541491998, 850341345692155, 826490944132718, 329513332018620, 41046816597282, 396581286424992, 488863267297267, 92023040998362, 529684488438507, 925328511390026, 524897846090435, 413156582909097, 840524616502482, 325719016994120, 402494835113608, 145033960690364, 43932113323388, 683561775499473, 434510534220939, 92584300328516, 763767269974656, 289837041593468, 11468527450938, 628247946152943, 8844724571683, 813851806959975, 72001988637120, 875394575395153, 70667866716476, 75304931994100, 226809172374264, 767059176444181, 45462007920789, 472607315695803, 325973946551448, 64200767729194, 534886246409921, 950408390792175, 492288777130394, 226746605380806, 944479111810431, 776057001143579, 658971626589122, 231918349590349, 699710172246548, 122457405264610, 643115611310737, 999072890586878, 203230862786955, 348112034218733, 240143417330886, 927148962961842, 661569511006072, 190334725550806, 763365444730995, 516228913786395, 846501182194443, 741210200995504, 511935604454925, 687689993302203, 631038090127480, 961606522916414, 138550017953034, 932105540686829, 215285284639233, 772628158955819, 496858298527292, 730971468815108, 896733219370353, 967083685727881, 607660822695530, 650953466617730, 133773994258132, 623283311953090, 436380836970128, 237114930094468, 115451711811481, 674593269112948, 140400921371770, 659335660634071, 536749311958781, 854645598266824, 303305169095255, 91430489108219, 573739385205188, 400604977158702, 728593782212529, 807432219147040, 893541884126828, 183964371201281, 422680633277230, 218817645778789, 313025293025224, 657253930848472, 747562211812373, 83456701182914, 470417289614736, 641146659305859, 468130225316006, 46960547227850, 875638267674897, 662661765336441, 186533085001285, 743250648436106, 451414956181714, 527954145201673, 922589993405001, 242119479617901, 865476357142231, 988987578447349, 430198555146088, 477890180119931, 844464003254807, 503374203275928, 775374254241792, 346653210679737, 789242808338116, 48503976498612, 604300186163323, 475930096252359, 860836853339514, 994513691290102, 591343659366796, 944852018048514, 82396968629164, 152776642436549, 916070996204621, 305574094667054, 981194179562189, 126174175810273, 55636640522694, 44670495393401, 74724541586529, 988608465654705, 870533906709633, 374564052429787, 486493568142979, 469485372072295, 221153171135022, 289713227465073, 952450431038075, 107298466441025, 938262809228861, 253919870663003, 835790485199226, 655456538877798, 595464842927075, 191621819564547]

flag = []
for i in ciphertext:
    if pow(i,(p-1)//2,p) == 1:
        flag.append('1')
    else:
        flag.append('0')

def bitstring_to_bytes(s):
    v = int(s, 2)
    b = bytearray()
    while v:
        b.append(v & 0xff)
        v >>= 8
    return bytes(b[::-1])
plain = ''.join(flag)
print(bitstring_to_bytes(plain))

Thanks for reading. Have a good day <3

Last updated