cipher = 892408374578063131162925795619920779766603018609992406621503024400320421262482556891045333045408815199768659578199823419716777827460090306221618906101139272423449131313434967763664295600593363990276765767066758967765012850672428517786210813209127040442832574380675662826137452780727264357 n = 17076697689025821279984148703479525857912324396375097877800474725170566885465833732966897433803722770843910606215420934526050277173030062927090405120718833473629930226217051580832179577629652910778242159108718885516149768995851175071714817922775555170553827627677999093195969471873530031984433631909841287167351534954860426002075822101506835880510505034002629168205724869128357383388034971402180363910826536064357845040799329301895842061729319929568340334416516796267886218679042058969927331452548377324349084816441144473807565907927986545026739667157223640848553663532280797054758912745891410981282851031085852562257 e = 3
# 破解密文 defget_flag(): i = 0 whileTrue: if(gmpy2.iroot(cipher+i*n, 3)[1] == True): flag_bin = int(gmpy2.iroot(cipher+x*n, 3)[0]) flag = hex(flag_bin)[2:-1].decode("hex") print(flag) break i += 1
defget_flag_for(): for x in range(0, 118720000): if(gmpy2.iroot(cipher+x*n, 3)[1] == 1): flag_bin = int(gmpy2.iroot(cipher+x*n, 3)[0]) print(flag_bin) flag = hex(flag_bin)[2:-1].decode("hex") print(flag) break
if __name__ == "__main__": get_flag_for() # get_flag()
from itertools import * from string import printable alphabet = list(range(256)) LETTER_FREQUENCY = { ' ': 0.25000, 'e': 0.12702, 't': 0.09056, 'a': 0.08167, 'o': 0.07507, 'i': 0.06966, 'n': 0.06749, 's': 0.06327, 'h': 0.06094, 'r': 0.05987, 'd': 0.04253, 'l': 0.04025, 'c': 0.02782, 'u': 0.02758, 'm': 0.02406, 'w': 0.02360, 'f': 0.02228, 'g': 0.02015, 'y': 0.01974, 'p': 0.01929, 'b': 0.01492, 'v': 0.00978, 'k': 0.00772, 'j': 0.00153, 'x': 0.00150, 'q': 0.00095, 'z': 0.00074 } defIndCo(s): N = len(s) frequency = [s.count(c) for c in alphabet] return sum(i**2 - i for i in frequency) / (N**2 - N) defCalKeyLength(s): res = [] for kl in range(2, 38): subs = [s[i::kl] for i in range(kl)] if sum(IndCo(si) for si in subs) / kl > 0.06: if all(map(lambda x: kl % x, res)): res.append(kl) return res defscore(s): score = 0 for c in s.lower(): if c in LETTER_FREQUENCY: score += LETTER_FREQUENCY[c] return score defRecoverKey(ct, kl): key = b'' subs = [ct[i::kl] for i in range(kl)] for s in subs: scores = [] for xor in range(256): xored_s = ''.join(chr(c ^ xor) for c in s) if all(c in printable for c in xored_s): scores.append((xor, score(xored_s))) key += bytes([max(scores, key=lambda x: x[1])[0]]) return key defVigenere_dec(cipher, key): keyCircle = cycle(key) pt = '' for c in cipher: pt += chr(c ^ next(keyCircle)) return pt defmain(): cipher = bytes.fromhex('1f124d150f1f460159124952072041541d584438011e0e175f780d1944190d1755451d0e141504470108120d264a05020918254a4d0b1c4e131644551d5c074d561517120d264a0802171739094144071a4604520849480c0a15131555442d1017080b1f3f17050e0b1f1759111e1d14150e4854085a07640d0108071b780b0b440e090a1e561345140b19150513434438021649010339070544010c461e5f181b57081a591b0849506401054913142546190c0b4e17125208085e440453544059052c1e5d490d0778130e11501a0e1211080e5311045b541d5844080903040c1825174144071a4604520849480c0a150104440b2e0f51080453400b1d07444e0d0111040a4144195d1754470b2e1e161b461e324609071d1e051e43594945074d5d13181207360d0312121b3f0c0c440e09041c431249471141150517120c230e51070b07400d03055010011360070e1417201954055544350d030e46143c0a4d0501050c141111024207104154085f440c0d121f011d7c461c07501b010756550a60104d541d1b6005640e1a1b01122446190c0b4e0b0159121b14150e4e5f5f590e641b190818077c46190c0b4e1612431e0858441c560154430d6e4a170a18533c0d0807501a0e1211051b57110a5b085442073201200d4a53240e0e18501f0b1a565508564406410154600d2b1b1a0e170778051a180803181e451e0e4144065b011b4318270e51080c533f1220440e090d1b58551b57010a5e061756506410201b4616390b094401204613600749571606596054590e641e190e460223160a12040d121e47124958070c471717120d264a14080903371806110104461c5f19121e') cipher = b''.join(bytes([c - 1]) for c in cipher) kls = CalKeyLength(cipher) print(f"All probable key length: {kls}") for kl in kls: key = RecoverKey(cipher, kl) print(f"Key: {key}") print(Vigenere_dec(cipher, key)) if __name__ == '__main__': main()
f = open('so.in') a = [] for i in range(2): s = f.readline() for j in range(16): a.append(int(s[j*3:j*3+2], 16)) print a key = 'h4mbur93r' table1 = [0]*256 table2 = [0]*256 for i in range(256): table1[i] = i table2[i] = ord(key[i % 9])
v9 = 0 for i in range(256): v9 = (table2[i] + v9 + table1[i]) % 256 v2 = table1[v9] table1[v9] = table1[i] table1[i] = v2
v6 = 0 v10 = 0 flag = '' for i in range(29): v6 += 1 v10 = (v10 + table1[v6]) % 256 v4 = table1[v10] table1[v10] = table1[v6] table1[v6] = v4 flag += chr(a[i] ^ table1[(table1[v10] + table1[v6]) % 256]) print flag
f = open('flag.txt') for i in range(13): s = f.readline() s = s.replace('401', '.') # long s = s.replace('SCU', '_') # short s = s.replace(' ', '/') s = s.replace('#', '') print s[:-1]