-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashing.py
44 lines (42 loc) · 1.41 KB
/
Hashing.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
import hashlib
def Hash(message,key):
x=message+key
result_hash = hashlib.md5(x.encode())
binary_hash=bin(int(result_hash.hexdigest(),16))[2:]
hashlist = list(binary_hash)
while len(hashlist) < 128:
hashlist.insert(0, '0')
binary_hash = ''.join(hashlist)
return binary_hash
def hmac(blocks,key):
ipad='00110110'*21
keylist=list(key)
message=''.join(blocks)
while len(keylist) < 168:
keylist.insert(0, '0')
outputofxor = bin(int(ipad, 2) ^ int(key, 2))[2:]
xorlist = list(outputofxor)
while len(xorlist) < 168:
xorlist.insert(0, '0')
outputofxor = ''.join(xorlist)
message=outputofxor+message
hash=bin(int(hashlib.sha1(message.encode()).hexdigest(), 16))[2:]
hashlist = list(hash)
while len(hashlist) < 168:
hashlist.insert(0, '0')
hash = ''.join(hashlist)
opad='01011100'*21
outputofxor = bin(int(opad, 2) ^ int(key, 2))[2:]
xorlist = list(outputofxor)
while len(xorlist) < 168:
xorlist.insert(0, '0')
outputofxor = ''.join(xorlist)
hash=outputofxor+hash
hash = bin(int(hashlib.sha1(hash.encode()).hexdigest(), 16))[2:]
hashlist = list(hash)
while len(hashlist) < 160:
hashlist.insert(0, '0')
hash = ''.join(hashlist)
return hash
#message='101010101010101010'
#print(bin(int(hashlib.sha1(message.encode()).hexdigest(),16))[2:])