其他分享
首页 > 其他分享> > cisco type 7 密文解密

cisco type 7 密文解密

作者:互联网

'''
选择明文攻击
根据已有密码和算法计算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为enc_pw的前两个字母
    seed = int(enc_pw[0:2])
    print("seed:",seed)
    val = 0
    #enc_pw中的每两个字母对应一个明文字母
    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'
    enc_pw = '102c13281d074f012843797f'+'\0'
    #enc_pw = '155e082d327a7e5611'+'\0'
    decode(xlat,enc_pw)

 

标签:tmp,enc,cisco,pw,val,9999,seed,密文,type
来源: https://www.cnblogs.com/xkdn/p/16667958.html