-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
68 lines (51 loc) · 1.73 KB
/
Copy pathutility.py
File metadata and controls
68 lines (51 loc) · 1.73 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
import hashlib
import codecs
import config
def hash_family(i):
result_size = config.LENGTH_BITMAP / 4 # how many bytes we want back
max_len = config.NUM_HASH_FAMILIES # how long can our i be (in decimal)
salt = str(i).zfill(max_len)[-max_len:]
def hash_member(x):
return hashlib.sha1(x.encode('utf-8') + salt).hexdigest()[-result_size:]
return hash_member
def init_hash_families(nhf):
hash_families = []
for i in range(nhf):
hash_families.append(hash_family(i))
return hash_families
def ip_file():
counter = 0
with codecs.open("access_log_Jul95", 'r') as file_handle:
with codecs.open("ip.txt", 'w') as f_handle:
for line in file_handle:
counter += 1
if counter > 100000:
break
split = line.split(" - - ")
f_handle.write(split[0])
f_handle.write("\n")
def get_binary_representation(number):
binary = "{0:b}".format(int(number, 16)) # give me the binary form of the hex representation of number
while len(binary) < config.LENGTH_BITMAP:
binary = "0" + binary
return binary
# least significant one position, it is equal to the length of the tail
def get_least_sign_bit(number):
if number == 0:
return config.LENGTH_BITMAP
b_number = get_binary_representation(number)
# print "binary = " + b_number
return config.LENGTH_BITMAP - 1 - b_number.rfind("1")
# same probability for even and odd
def my_hash(element):
if hash(element) % 2 == 0:
return 1
else:
return -1
class proceed:
def __init__(self):
self.c = "y"
def change(self):
self.c = "n"
def get_c(self):
return self.c