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))
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 ="")
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))