flag1 = b"moectf{" data = eval("["+",".join(open("result.log").readlines())+"]") for x in data: strxor = lambda x, y: bytes([a ^ b for a, b inzip(x, y)]) tmps = [] for x in data: # 已知前面部分明文 print((tmp := strxor(flag1, x))) tmps.append(tmp)
for x in data: strxor = lambda x, y: bytes([a ^ b for a, b inzip(x, y)]) # print(len(x)) assertlen(x) == 72 tmps = [] tmps2 = [] for x in data: # 已知前面部分明文 moectf{ tmp = strxor(flag1, x) tmps.append(tmp) # You will learn how to ... 拼不出来
for i inrange(100): tmp2 = tmps[i][1:6] # print(tmp2) for j inrange(i+1,100): if tmp2 in tmps[j]: print(i,j,tmps[i],tmps[j])
import binascii import base64 import string from itertools import *
defbxor(a, b): # xor two byte strings of different lengths iflen(a) > len(b): returnbytes([x ^ y for x, y inzip(a[:len(b)], b)]) else: returnbytes([x ^ y for x, y inzip(a, b[:len(a)])])
defhamming_distance(b1, b2): differing_bits = 0 for byte in bxor(b1, b2): differing_bits += bin(byte).count("1") return differing_bits
# text = '' # with open("6.txt","r") as f: # for line in f: # text += line
# b = base64.b64decode(text)
defbreak_single_key_xor(text): key = 0 possible_space=0 max_possible=0 letters = string.ascii_letters.encode('ascii') for a inrange(0, len(text)): maxpossible = 0 for b inrange(0, len(text)): if(a == b): continue c = text[a] ^ text[b] if c notin letters and c != 0: continue maxpossible += 1 if maxpossible>max_possible: max_possible=maxpossible possible_space=a key = text[possible_space]^ 0x20 returnchr(key)
c='49380d773440222d1b421b3060380c3f403c3844791b202651306721135b6229294a3c3222357e766b2f15561b35305e3c3b670e49382c295c6c170553577d3a2b791470406318315d753f03637f2b614a4f2e1c4f21027e227a4122757b446037786a7b0e37635024246d60136f7802543e4d36265c3e035a725c6322700d626b345d1d6464283a016f35714d434124281b607d315f66212d671428026a4f4f79657e34153f3467097e4e135f187a21767f02125b375563517a3742597b6c394e78742c4a725069606576777c314429264f6e330d7530453f22537f5e3034560d22146831456b1b72725f30676d0d5c71617d48753e26667e2f7a334c731c22630a242c7140457a42324629064441036c7e646208630e745531436b7c51743a36674c4f352a5575407b767a5c747176016c0676386e403a2b42356a727a04662b4446375f36265f3f124b724c6e346544706277641025063420016629225b43432428036f29341a2338627c47650b264c477c653a67043e6766152a485c7f33617264780656537e5468143f305f4537722352303c3d4379043d69797e6f3922527b24536e310d653d4c33696c635474637d0326516f745e610d773340306621105a7361654e3e392970687c2e335f3015677d4b3a724a4659767c2f5b7c16055a126820306c14315d6b59224a27311f747f336f4d5974321a22507b22705a226c6d446a37375761423a2b5c29247163046d7e47032244377508300751727126326f117f7a38670c2b23203d4f27046a5c5e1532601126292f577776606f0c6d0126474b2a73737a41316362146e581d7c1228717664091c' salt="WeAreDe1taTeam" si2=cycle(salt) nosalt='' for i inrange(int(len(c)/2)): temp=c[i*2:i*2+2] # print(binascii.a2b_hex(temp)) temphex_int=ord(binascii.a2b_hex(temp).decode()) # p = chr(temphex_int ^ ord(next(si2)) ^ ord(next(ki2))) temp_re= hex(temphex_int ^ ord(next(si2)))[2:].zfill(2) nosalt=nosalt+temp_re