-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
62 lines (54 loc) · 1.6 KB
/
model.py
File metadata and controls
62 lines (54 loc) · 1.6 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
from hashlib import sha1, sha224, sha256, sha384, sha512
class Blockchain:
def __init__(self):
self.bl = []
self.nu = 0
def append(self, block):
self.bl.append(block)
self.nu += 1
class Block:
def __init__(self):
self.tr = []
self.nu = 0
def append(self, transaction):
self.tr.append(transaction)
self.nu += 1
class Transaction:
def __init__(self, fr, to, am, fe):
self.fr = fr
self.to = to
self.am = am
self.fe = fe
class Users:
def __init__(self):
self.us = []
self.nu = 0
def append(self, user):
self.us.append(user)
self.nu += 1
class User:
def __init__(self, us=Users):
self.ID = sha256(us.nu.encode('utf-8')).hexdigest()
def binary(string):
return "".join([format(ord(i), 'b') for i in string])
def hash(block, string):
if block % 5 == 0: return binary(sha1(string.encode('utf-8')).hexdigest())
elif block % 5 == 1: return binary(sha224(string.encode('utf-8')).hexdigest())
elif block % 5 == 2: return binary(sha256(string.encode('utf-8')).hexdigest())
elif block % 5 == 3: return binary(sha384(string.encode('utf-8')).hexdigest())
else: return binary(sha512(string.encode('utf-8')).hexdigest())
def leadingOnes(string):
i = 0
while(string[i] != '0'):
i += 1
if i == len(string): return i
return i
'''
tries = 0
max1 = -1
while(max1 != 4):
max1 = max(max1, leadingOnes(hash(2, str(tries))))
print(tries,leadingOnes(hash(2, str(tries))))
tries += 1
print(tries, hash(2, str(tries)))
'''