-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_bloom.py
executable file
·103 lines (91 loc) · 3.74 KB
/
generate_bloom.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import secp256k1 #https://github.com/iceland2k14/secp256k1
from datetime import datetime
import os
import sys
import multiprocessing as mp
#==============================================================================
f_list = ['settings1.txt', 'settings2.txt', 'bloom1.bf', 'bloom2.bf']
arr = os.listdir()
for f in arr:
if f in f_list:
os.remove(f)
#==============================================================================
P_table = []
pk = 1;
for i in range(256):
P_table.append(secp256k1.scalar_multiplication(pk))
pk *= 2
print(f"[{datetime.now().strftime("%H:%M:%S")}] P_table generated")
#==============================================================================
start_range = 44
end_range = 45
block_width = 20
start_point = P_table[start_range]
end_point = P_table[end_range]
point_05 = secp256k1.scalar_multiplication(57896044618658097711785492504343953926418782139537452191302581570759080747169)
search_pub = '0307cc34433cb76bf50ee2b2a5227ac06ba3019ee52c6ee0dffdcc8818c627c8e4'
puzzle_point = secp256k1.pub2upub(search_pub)
puzzle_point_05 = secp256k1.point_addition(puzzle_point, point_05)
puzzle_point_divide2 = secp256k1.point_multiplication(puzzle_point, 57896044618658097711785492504343953926418782139537452191302581570759080747169)
first_point = P_table[start_range - 1]
second_point = P_table[start_range - 2]
P1 = secp256k1.point_subtraction(puzzle_point_divide2, first_point)
P2 = secp256k1.point_subtraction(puzzle_point_divide2, second_point)
Q1 = secp256k1.point_addition(P1, P2)
Q2 = secp256k1.point_addition(puzzle_point_divide2, Q1)
starting_point = Q2
stride_sum = 0
settingsFile1 = 'settings1.txt'
settingsFile2 = 'settings2.txt'
f1 = open(settingsFile1, "w")
f1.write(f"{secp256k1.point_to_cpub(starting_point)}\n")
f1.write(f"{stride_sum}\n")
f1.close()
f2 = open(settingsFile2, "w")
f2.write(f"{secp256k1.point_to_cpub(starting_point)}\n")
f2.write(f"{stride_sum}\n")
f2.close()
print(f"[{datetime.now().strftime("%H:%M:%S")}] Settings written to file")
#==============================================================================
def bloom_create1():
bloomfile1 = 'bloom1.bf'
G = secp256k1.scalar_multiplication(1)
_elem = (2 * (2**block_width))
_fp = 0.000001
_bits, _hashes = secp256k1.bloom_para(_elem, _fp)
_bf = (b'\x00') * (_bits//8)
print(f'[{datetime.now().strftime("%H:%M:%S")}] Creating bloomfile1')
P = puzzle_point
for i in range(2**block_width):
P = secp256k1.point_addition(P, G)
secp256k1.add_to_bloom(secp256k1.point_to_cpub(P), _bits, _hashes, _bf)
print(f'[{datetime.now().strftime("%H:%M:%S")}] Writing Bloomfilter to {bloomfile1}')
secp256k1.dump_bloom_file(bloomfile1, _bits, _hashes, _bf, _fp, _elem)
def bloom_create2():
bloomfile2 = 'bloom2.bf'
G = secp256k1.scalar_multiplication(1)
_elem = (2 * (2**block_width))
_fp = 0.000001
_bits, _hashes = secp256k1.bloom_para(_elem, _fp)
_bf = (b'\x00') * (_bits//8)
print(f'[{datetime.now().strftime("%H:%M:%S")}] Creating bloomfile2')
P = puzzle_point_05
for i in range(2**block_width):
P = secp256k1.point_addition(P, G)
secp256k1.add_to_bloom(secp256k1.point_to_cpub(P), _bits, _hashes, _bf)
print(f'[{datetime.now().strftime("%H:%M:%S")}] Writing Bloomfilter to {bloomfile2}')
secp256k1.dump_bloom_file(bloomfile2, _bits, _hashes, _bf, _fp, _elem)
def main():
p1 = mp.Process(target=bloom_create1)
p2 = mp.Process(target=bloom_create2)
p1.start()
p2.start()
p1.join()
p2.join()
out()
def out():
print(f'[{datetime.now().strftime("%H:%M:%S")}] Done. Press <ENTER> to exit...')
input()
#==============================================================================
if __name__ == '__main__':
main()