-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hash.py
66 lines (53 loc) · 1.19 KB
/
test_hash.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
from datetime import datetime
import pytz
import json
x = {
"_tt": "DGP",
"bi": 1145,
"bs": 1,
"g": [0.3205018616, 0.1532438682],
"hs": 1.0,
# "id": 21078830,
"la": 1,
"le": 735,
"r": 0,
"s": True,
"tn": "update me",
"vs": 1.0,
}
startTime = datetime.now(pytz.utc)
unique = set()
import string
ALPHABET = (
string.ascii_uppercase + string.ascii_lowercase + string.digits + "-_"
)
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
BASE = len(ALPHABET)
SIGN_CHARACTER = "$"
def num_encode(n):
if n < 0:
return SIGN_CHARACTER + num_encode(-n)
s = []
while True:
n, r = divmod(n, BASE)
s.append(ALPHABET[r])
if n == 0:
break
return "".join(reversed(s))
def num_decode(s):
if s[0] == SIGN_CHARACTER:
return -num_decode(s[1:])
n = 0
for c in s:
n = n * BASE + ALPHABET_REVERSE[c]
return n
for num in range(100):
x["g"][0] += num
x["g"][1] += num
p = hash(json.dumps(x))
# print(str(p))
unique.add(p)
print(str(p))
print(num_encode(p))
print("Values = %s" % len(unique))
print("Taken %s", (datetime.now(pytz.utc) - startTime))