-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmizipCalcKeys.py
60 lines (46 loc) · 1.27 KB
/
mizipCalcKeys.py
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
#!/usr/bin/env python
# This script is an implementation of lua code written by Iceman:
# https://github.com/iceman1001/proxmark3/blob/master/client/scripts/calc_mizip.lua
# Thanks to him and y0no for this script:
# https://gist.github.com/y0no/70565a8d09203122181f3b3a08bffcbd
import sys
xortable = (
('001', '09125a2589e5', 'F12C8453D821'),
('002', 'AB75C937922F', '73E799FE3241'),
('003', 'E27241AF2C09', 'AA4D137656AE'),
('004', '317AB72F4490', 'B01327272DFD'),
)
def calcKey(uid, xorkey, keytype):
p = []
idx = {
'A': (0,1,2,3,0,1),
'B': (2,3,0,1,2,3),
}.get(keytype)
for i,j in enumerate(idx):
p.append('%02x'% (uid[j] ^ xorkey[i]))
return ''.join(p)
def hextostr(hexa):
return bytes.fromhex(hexa)
def calc(UID):
_uid = UID
if len(_uid) != 8:
print('Your UID has not the good length')
sys.exit(1)
try:
uid = hextostr(_uid)
except ValueError:
print('Your UID is not a valid one')
sys.exit(1)
ka = []
kb = []
ka.append('A0A1A2A3A4A5')
kb.append('B4C132439EEF')
for sec, xorA, xorB in xortable:
keyA = calcKey(uid, hextostr(xorA), 'A')
keyB = calcKey(uid, hextostr(xorB), 'B')
ka.append(keyA.upper())
kb.append(keyB.upper())
keys = []
keys.append(ka)
keys.append(kb)
return keys