20221011
-
AES加密模式为CBC,初始化矢量即IV为零,填充为01-00。
-
此外,相应的密钥在身份证件上的机器可读区域(MRZ)中,但缺一位,需要使用对应方法复原
12345678 <8 <<< 1110182 <111116?<<<<<<<<<<<<<<< 4
-
cipher="9MgYwmuPrjiecPMx61O6zIuy3MtIXQQ0E59T3xB6u0Gyf1gYs2i3K9Jxaa0zj4gTMazJuApwd6+jdyeI5iGHvhQyDHGVlAuYTgJrbFDrfB22Fpil2NfNnWFBTXyf7SDI"
-
Kenc取自护照上的数字加密的结果
-
Kenc与明文解密
护照上的缺失位
https://www.cnblogs.com/catzhou/p/12711979.html
10:1-9的验证码,验证算法如下
int Compute(string source)
{
string s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int[] w = new int[] { 7, 3, 1 };
int c = 0;
for (int i = 0; i < source.Length; i++)
{
if (source[i] == '<')
continue;
c += s.IndexOf(source[i]) * w[i % 3];
}
c %= 10;
return c;
}
12345678 <8 <<< 1110182 <111116?<<<<<<<<<<<<<<< 4
校验位的计算方法为不断重复7 3 1并且进行加权 模10 计算
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
得到缺失的校验位为 7
Kenc
import hashlib
passport = '12345678<8<<<1110182<1111167<<<<<<<<<<<<<<<4'
num = passport[:10]
birth = passport[13:20]
arrive = passport[21:28]
mrz = num+birth+arrive
h = hashlib.sha1(mrz.encode()).hexdigest()
print(h)
链接Kseed与c得到D
h = "a095f0fdfe51e6ab3bf5c777302c473e7a59be65"
k_seed = h[:32]
c = '00000001'
D = k_seed + c
h_D = hashlib.sha1(bytes.fromhex(D)).hexdigest()
print(h_D)
D=eb8645d97ff725a998952aa381c5307909962536
取D的前16位和后16位并进行奇偶校验,得到key值
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))
return a1[2:]
h = "a095f0fdfe51e6ab3bf5c777302c473e7a59be65"
k_seed = h[:32]
c = '00000001'
D = k_seed + c
h_D = hashlib.sha1(bytes.fromhex(D)).hexdigest()
ka = h_D[:16]
kb = h_D[16:32]
k_1 = jiaoyan(ka)
k_2 = jiaoyan(kb)
key = k_1 + k_2
print(key)
# ea8645d97ff725a898942aa280c43179
最后使用key对明文进行解密
cipher="9MgYwmuPrjiecPMx61O6zIuy3MtIXQQ0E59T3xB6u0Gyf1gYs2i3K9Jxaa0zj4gTMazJuApwd6+jdyeI5iGHvhQyDHGVlAuYTgJrbFDrfB22Fpil2NfNnWFBTXyf7SDI"
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'
最终结果为 Kryptographie