-
Notifications
You must be signed in to change notification settings - Fork 1
/
func1_logic.py
59 lines (53 loc) · 1.71 KB
/
func1_logic.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
inkey = [4038229138, 3264621612, 3708831499, 1170209094, 2539419318, 2296419940, 2385001168, 2732828167, 1519857378, 3778844499, 3035290357, 952667762, 3777642813, 3261289113, 1625043434, 1722925685]
tmp = [0] * 0x10
for i in range(0x10):
tmp[i] = inkey[i]
tpv = [
# (dest, a, b, pre)
(0x4, 0x0, 0xc, 0x7),
(0x8, 0x4, 0x0, 0x9),
(0xc, 0x8, 0x4, 0xd),
(0x0, 0xc, 0x8, 0x12),
(0x9, 0x5, 0x1, 0x7),
(0xd, 0x9, 0x5, 0x9),
(0x1, 0xd, 0x9, 0xd),
(0x5, 0x1, 0xd, 0x12),
(0xe, 0xa, 0x6, 0x7),
(0x2, 0xe, 0xa, 0x9),
(0x6, 0x2, 0xe, 0xd),
(0xa, 0x6, 0x2, 0x12),
(0x3, 0xf, 0xb, 0x7),
(0x7, 0x3, 0xf, 0x9),
(0xb, 0x7, 0x3, 0xd),
(0xf, 0xb, 0x7, 0x12),
(0x1, 0x0, 0x3, 0x7),
(0x2, 0x1, 0x0, 0x9),
(0x3, 0x2, 0x1, 0xd),
(0x0, 0x3, 0x2, 0x12),
(0x6, 0x5, 0x4, 0x7),
(0x7, 0x6, 0x5, 0x9),
(0x4, 0x7, 0x6, 0xd),
(0x5, 0x4, 0x7, 0x12),
(0xb, 0xa, 0x9, 0x7),
(0x8, 0xb, 0xa, 0x9),
(0x9, 0x8, 0xb, 0xd),
(0xa, 0x9, 0x8, 0x12),
(0xc, 0xf, 0xe, 0x7),
(0xd, 0xc, 0xf, 0x9),
(0xe, 0xd, 0xc, 0xd),
(0xf, 0xe, 0xd, 0x12),
]
from collections import Counter
print(Counter([v[3] for v in tpv]))
for i in range(0x14, 0, -2):
for dest, a, b, pre in tpv:
s = tmp[a] + tmp[b]
s &= 0xffffffff
s = (s >> pre) | (s << (32 - pre))
s &= 0xffffffff
tmp[dest] ^= s
outkey = []
for i in range(0x10):
outkey.append((inkey[i] + tmp[i]) & 0xffffffff)
print(outkey)
[589930174, 719055133, 1734469938, 3994688129, 3777287184, 3002432264, 142948376, 3145054283, 3884640667, 2444015112, 1800754206, 966904195, 2210516158, 667738657, 3513180722, 768092542]