# sage defrational_to_contfrac(x,y): # Converts a rational x/y fraction into a list of partial quotients [a0, ..., an] a = x // y pquotients = [a] while a * y != x: x, y = y, x - a * y a = x // y pquotients.append(a) return pquotients
defconvergents_from_contfrac(frac): # computes the list of convergents using the list of partial quotients convs = []; for i inrange(len(frac)): convs.append(contfrac_to_rational(frac[0 : i])) return convs
defcontfrac_to_rational (frac): # Converts a finite continued fraction [a0, ..., an] to an x/y rational. iflen(frac) == 0: return (0,1) num = frac[-1] denom = 1 for _ inrange(-2, -len(frac) - 1, -1): num, denom = frac[_] * num + denom, num return (num, denom)
c = 6755916696778185952300108824880341673727005249517850628424982499865744864158808968764135637141068930913626093598728925195859592078242679206690525678584698906782028671968557701271591419982370839581872779561897896707128815668722609285484978303216863236997021197576337940204757331749701872808443246927772977500576853559531421931943600185923610329322219591977644573509755483679059951426686170296018798771243136530651597181988040668586240449099412301454312937065604961224359235038190145852108473520413909014198600434679037524165523422401364208450631557380207996597981309168360160658308982745545442756884931141501387954248 e = 8614531087131806536072176126608505396485998912193090420094510792595101158240453985055053653848556325011409922394711124558383619830290017950912353027270400567568622816245822324422993074690183971093882640779808546479195604743230137113293752897968332220989640710311998150108315298333817030634179487075421403617790823560886688860928133117536724977888683732478708628314857313700596522339509581915323452695136877802816003353853220986492007970183551041303875958750496892867954477510966708935358534322867404860267180294538231734184176727805289746004999969923736528783436876728104351783351879340959568183101515294393048651825 n = 19873634983456087520110552277450497529248494581902299327237268030756398057752510103012336452522030173329321726779935832106030157682672262548076895370443461558851584951681093787821035488952691034250115440441807557595256984719995983158595843451037546929918777883675020571945533922321514120075488490479009468943286990002735169371404973284096869826357659027627815888558391520276866122370551115223282637855894202170474955274129276356625364663165723431215981184996513023372433862053624792195361271141451880123090158644095287045862204954829998614717677163841391272754122687961264723993880239407106030370047794145123292991433
defegcd(a, b): if a == 0: return (b, 0, 1) g, x, y = egcd(b % a, a) return (g, y - (b // a) * x, x)
defmod_inv(a, m): g, x, _ = egcd(a, m) return (x + m) % m
defisqrt(n): x = n y = (x + 1) // 2 while y < x: x = y y = (x + n // x) // 2 return x defcrack_rsa(e, n): frac = rational_to_contfrac(e, n) convergents = convergents_from_contfrac(frac) for (k, d) in convergents: if k != 0and (e * d - 1) % k == 0: phi = (e * d - 1) // k s = n - phi + 1 # check if x*x - s*x + n = 0 has integer roots D = s * s - 4 * n if D >= 0: sq = isqrt(D) if sq * sq == D and (s + sq) % 2 == 0: return d
d = crack_rsa(e, n) m = hex(pow(c, d, n))[2:] print(bytes.fromhex(m))
phi_n = 1 for i inrange(1,16): value = eval('P' + str(i)) phi_n *= value-1 print(phi_n) d = gmpy2.invert(e, phi_n) m = gmpy2.powmod(c,d,n) print(binascii.unhexlify(hex(m)[2:]))
得到flag
Vigenère
先把flag标志爆出来
考虑括号内的语义
5ign0r较为有语义,考虑密钥为6位,那么猜个kfckfc
得到flag,感觉是法语
babyxor
使用python脚本爆破key
1 2 3 4 5 6 7 8 9 10
from binascii import a2b_hex ciphertext=b'e9e3eee8f4f7bffdd0bebad0fcf6e2e2bcfbfdf6d0eee1ebd0eabbf5f6aeaeaeaeaeaef2' for key inrange(255): flag='' for i inrange(len(ciphertext)//2): c = int(ciphertext[i*2:i*2+2],base=16) flag+=(chr(c^key)) if('flag'in flag): print(flag) exit()
import libnum ciphertext='dd4388ee428bdddd5865cc66aa5887ffcca966109c66edcca920667a88312064' defdecrypt(c,key0,key1): c=eval('0x'+c) for i inrange(256): if((c+256*i-key1)%key0==0): return (c+256*i-key1)//key0 return -1
for key0 inrange(1,256): for key1 inrange(256): flag='' length=len(ciphertext)//2 for i inrange(length): f = decrypt(ciphertext[i*2:i*2+2],key0,key1) if(f<0): break flag+=chr(f) if('flag'in flag): print(flag) exit()
得到flag
babyencoding
题目如下:
1 2 3
part 1 of flag: ZmxhZ3tkYXp6bGluZ19lbmNvZGluZyM0ZTBhZDQ= part 2 of flag: MYYGGYJQHBSDCZJRMQYGMMJQMMYGGN3BMZSTIMRSMZSWCNY= part 3 of flag: =8S4U,3DR8SDY,C`S-F5F-C(S,S<R-C`Q9F8S87T`
for i in list1: for j in list2: back = str(i) + '.' + str(j) url = str(url1) + '/' + back print(back + ' ', end='') print(requests.get(url).status_code)
array=[0x75553A1E, 0x7B583A03, 0x4D58220C, 0x7B50383D, 0x736B3819] flag='' for h in array: h = str(hex(h^0x12345678)) for j inrange(1,5): flag+=chr(int(h[10-j*2:12-j*2],16)) print(flag)