-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableGenerator.py
More file actions
72 lines (58 loc) · 2.49 KB
/
Copy pathTableGenerator.py
File metadata and controls
72 lines (58 loc) · 2.49 KB
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
69
70
71
72
import json
import hashlib
class TableGenerator(object):
def Generate(self, numDigits, lenChains):
dataFile = 'data{0}.json'.format(numDigits)
dictionaryFile = 'dictionary{0}.json'.format(numDigits)
f = open(dataFile)
data = json.load(f)
p = open(dictionaryFile)
alreadyComputed = json.load(p)
dictionary = {}
print("Generating chains")
for i in range(len(data)): # Number of chains
if (data[i] not in alreadyComputed.keys()):
t = hashlib.sha256(data[i].encode('utf-8')).hexdigest()
for j in range(lenChains - 1): # Length of chains
t = t[:numDigits]
t = hashlib.sha256(t.encode('utf-8')).hexdigest()
t = t[:numDigits]
dictionary.update({"{0}".format(data[i]): "{0}".format(t)})
with open(dictionaryFile) as fp:
dictObj = json.load(fp)
dictObj.update(dictionary)
with open(dictionaryFile, 'w') as outfile:
json.dump(dictObj, outfile,
indent=4,
separators=(',', ': '))
f.close()
print("Finished generating chain")
def GenerateLarge(self, numDigits, lenChains, fileNumber, start, end):
dataFile = 'data{0}.json'.format(numDigits)
dictionaryFile = 'dictionary{0}.json'.format(fileNumber)
f = open(dataFile)
data = json.load(f)
# p = open(dictionaryFile)
# alreadyComputed = json.load(p)
dictionary = {}
print("Generating chains")
# for i in range(len(data)): # Number of chains
for i in range(start, end):
# if (data[i] not in alreadyComputed.keys()):
t = hashlib.sha256(data[i].encode('utf-8')).hexdigest()
for j in range(lenChains - 1): # Length of chains
t = t[:numDigits]
# t = json.dumps(t).encode('utf-8')
# t = hashlib.sha256(t).hexdigest()
t = hashlib.sha256(t.encode('utf-8')).hexdigest()
t = t[:numDigits]
dictionary.update({"{0}".format(data[i]): "{0}".format(t)})
with open(dictionaryFile) as fp:
dictObj = json.load(fp)
dictObj.update(dictionary)
with open(dictionaryFile, 'w') as outfile:
json.dump(dictObj, outfile,
indent=4,
separators=(',', ': '))
f.close()
print("Finished generating chain")