-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_generator.py
90 lines (74 loc) · 3.07 KB
/
hash_generator.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
import hashlib
def sha256_hash(string_input):
"""
Generate the SHA-256 hash (256-bit) of the opcode.
Returns:
str: 256-bit binary string representing the hash of the opcode
"""
return bin(int(hashlib.sha256(string_input.encode('utf-8')).hexdigest(), 16))[2:].zfill(256)
def sha512_hash(string_input):
"""
Generate the SHA-512 hash (512-bit) of the opcode.
Returns:
str: 512-bit binary string representing the hash of the opcode
"""
return bin(int(hashlib.sha512(string_input.encode('utf-8')).hexdigest(), 16))[2:].zfill(512)
def md5_hash(string_input):
"""
Generate the MD5 hash (128-bit) of the opcode.
Returns:
str: 128-bit binary string representing the hash of the opcode
"""
return bin(int(hashlib.md5(string_input.encode('utf-8')).hexdigest(), 16))[2:].zfill(128)
def simhash_768(string_input):
"""
Generate the SimHash-768 by combining SHA-512 and SHA-256.
Returns:
str: 768-bit binary string by concatenating SHA-512 and SHA-256 hashes
"""
sha512_part = sha512_hash(string_input)
sha256_part = sha256_hash(string_input)
return sha512_part + sha256_part # 512 bits + 256 bits = 768 bits
def simhash_896(string_input):
"""
Generate the SimHash-896 by combining SHA-512, SHA-256, and MD5.
Returns:
str: 896-bit binary string by concatenating SHA-512, SHA-256, and MD5 hashes
"""
sha512_part = sha512_hash(string_input)
sha256_part = sha256_hash(string_input)
md5_part = md5_hash(string_input)
return sha512_part + sha256_part + md5_part # 512 + 256 + 128 = 896 bits
def simhash_384(string_input):
"""
Generate the SimHash-384 by combining SHA-256 and MD5.
Returns:
str: 384-bit binary string by concatenating SHA-256 and MD5 hashes
"""
sha256_part = sha256_hash(string_input)
md5_part = md5_hash(string_input)
return sha256_part + md5_part # 256 bits + 128 bits = 384 bits
def simhash_1024(string_input):
"""
Generate the SimHash-1024 by combining two SHA-512 hashes.
Returns:
str: 1024-bit binary string by concatenating two SHA-512 hashes
"""
sha512_part1 = sha512_hash(string_input)
sha512_part2 = bin(int(hashlib.sha512(string_input[::-1].encode('utf-8')).hexdigest(), 16))[2:].zfill(512) # Reverse opcode for second hash
return sha512_part1 + sha512_part2 # 512 bits + 512 bits = 1024 bits
def display_all_hashes(string_input):
"""
Display all hash variants (SHA-256, SHA-512, MD5, and SimHash values) for the opcode.
Outputs:
Prints the binary hash values for different hash functions and SimHash combinations
"""
print(f"Opcode: {string_input}")
print(f"SHA-256 Hash: {sha256_hash(string_input)}")
print(f"SHA-512 Hash: {sha512_hash(string_input)}")
print(f"MD5 Hash: {md5_hash(string_input)}")
print(f"SimHash-768: {simhash_768(string_input)}")
print(f"SimHash-896: {simhash_896(string_input)}")
print(f"SimHash-384: {simhash_384(string_input)}")
print(f"SimHash-1024: {simhash_1024(string_input)}")
print("-" * 80)