1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| ''' 选择明文攻击 根据已有密码和算法计算xlat ''' def getxlat(enc_pw,dec_pw): xlat = [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999,9999, 9999, 9999, 9999, 9999, 9999, 9999,9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999,9999, 9999, 9999, 9999, 9999, 9999, 9999] seed = int(enc_pw[0:2]) print("seed:",seed) val = 0 for i in range(2,len(enc_pw)): print(i) if i%2 == 0 and i >2 : seed = seed +1 xlat[seed] = val ^ ord(dec_pw[int(i/2 - 2)]) val = 0 print(seed,xlat[seed]) val = val *16 tmp = enc_pw[i].upper() if tmp >= '0' and tmp <= '9' : val = val + ord(tmp) - ord('0') continue
if tmp >= 'A' and tmp <= 'F' : val = val + ord(tmp) - ord('A') + 10; continue print(xlat) return xlat
def decode(xlat,enc_pw): test_pw = '' seed = int(enc_pw[0:2]) print("seed:",seed) val = 0
for i in range(2,len(enc_pw)): print(i) if i%2 == 0 and i >2 : seed = seed +1 test_pw_char = chr(val ^xlat[seed]) test_pw += test_pw_char val = 0 print(seed,xlat[seed],test_pw_char) val = val *16 tmp = enc_pw[i].upper() if tmp >= '0' and tmp <= '9' : val = val + ord(tmp) - ord('0') continue
if tmp >= 'A' and tmp <= 'F' : val = val + ord(tmp) - ord('A') + 10; continue print(test_pw) if __name__ == "__main__" : enc_pw = '1100320c1843080143797f'+'\0' dec_pw = 'ruijie@123' xlat = getxlat(enc_pw,dec_pw) xlat = [9999, 42, 64, 35, 35, 87, 120, 102, 94, 99, 79, 117, 114, 71, 101, 114, 42, 109, 65, 114, 75, 76, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999] enc_pw = '1100320c1843080143797f'+'\0' decode(xlat,enc_pw)
|