-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_settings.py
68 lines (51 loc) · 1.34 KB
/
gen_settings.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
61
62
63
64
65
66
67
68
import sys
from math import floor
class SettingsFile:
def __init__(self, filename):
self.filename = filename
self.file = open(filename, "w")
self.lines = []
def line(self, line):
self.lines.append(line)
def size(self):
return len(self.lines)
def save(self):
count = len(self.lines)
self.file.write(str(IC) + " " + str(count) + " " + str(count)+ "\n")
for line in self.lines:
self.file.write(line)
self.file.close()
if len(sys.argv) != 3:
print "Usage: " + sys.argv[0] + " <secret_key_file> <settings_files_prefix>"
sys.exit(0)
key_file = open(sys.argv[1], "r")
settings_files = []
for i in range (0, 4):
settings_files.append(SettingsFile(sys.argv[2] + str(i)))
key = []
IC = 0
for line in key_file.readlines():
line = line.strip()
if len(line):
skey = int(line, 16)
IC += float(skey)/256
key.append(skey)
key_file.close()
IC -= floor(IC)
Y = int(IC*100.0)
print "Key#, filename, lines"
def out_vals(Y):
# print Y
B = Y
N = Y%4
SK = key[B]
key_idx = ""
for i in range(0, B):
settings_files[N].line("%.2x %d" % (SK, N) + "\n")
idx = settings_files[N].size() - B
print "| %.2d | %s | %d - %d |" % (B, settings_files[N].filename, idx, idx + B - 1)
for i in range(0, 16):
Y = (5*Y + 1)%16
out_vals(Y)
for sf in settings_files:
sf.save()