MysteryTwisterC3 AES key - encoded in the machine readable zone of a European ePassport
参考:
https://www.codenong.com/cs109540921/
https://blog.csdn.net/weixin_48392428/article/details/117227205
1 求未知数字
利用以下代码能求出校验位的问号是7。
a = [1,1,1,1,1,6]
b = [7,3,1,7,3,1]
for i in range(0,6):
c = c + a[i]*b[i]
res = c % 10
print (res)
#res = 7
2 根据得到的数字计算出key,并解密
2.1 求Kseed
把证件的那些数字和校验位,直接sha1散列,然后取前16位即可。
H_information = sha1(information.encode()).hexdigest()
#十进制先变为二进制散列再换成十六进制
K_seed = H_information[:32]# 取前16位
2.2 求Ka和Kb
把之前生成的Kseed和c级联,然后再进行一次sha1散列生成了d,然后ka是d的前十六位,kb是d的后十六位。
c = '00000001'
#0x00000001
d = K_seed + c
#print(d)
H_d = sha1(codecs.decode(d,"hex")).hexdigest()
#十六进制先变为二进制散列再换成十六进制
#print(H_d)
ka = sha1(codecs.decode(d,"hex")).hexdigest()[:16]
kb = sha1(codecs.decode(d,"hex")).hexdigest()[16:32]
2.3 对Ka和Kb奇偶校验生成key
算1的个数并且把第八位当作奇偶校验位。
k_1 = jiaoyan(ka)
k_2 = jiaoyan(kb)
key = k_1 + k_2
print(key)
#ea8645d97ff725a898942aa280c43179
m=AES.new(binascii.unhexlify(key),AES.MODE_CBC,binascii.unhexlify(IV))
print(m.decrypt(cipher))
#b'Herzlichen Glueckwunsch. Sie haben die Nuss geknackt. Das Codewort lautet: Kryptographie!\x01\x00\x00\x00\x00\x00\x00'
#奇偶校验位的判断
def jiaoyan(x):
k = []
a = bin(int(x,16))[2:]
for i in range(0,len(a),8):
if (a[i:i+7].count("1"))%2 == 0:
k.append(a[i:i+7])
k.append('1')
else :
k.append(a[i:i+7])
k.append('0')
a1 = hex(int(''.join(k),2))
#print("this is " + x + "---" +a1)
return a1[2:]
'Herzlichen Glueckwunsch. Sie haben die Nuss geknackt. Das Codewort lautet: Kryptographie!
Answer: Kryptographie