加密 exp

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
import hashlib
import os


def generate_salt(length=16):
"""生成指定长度的盐值"""
return os.urandom(length)


def md5_hash_with_salt(input_string, salt=None):
"""计算带盐值的MD5哈希"""
if salt is None:
salt = generate_salt()
hasher = hashlib.md5()
# 将输入字符串与盐值结合
hasher.update(input_string.encode("utf-8") + salt)
# 获取哈希值
hash_value = hasher.hexdigest()
return hash_value, salt


print(
"""
.----------------. .----------------. .-----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| | _____ _____ | || | __ | || | ____ _____ | || | ________ | || | ____ ____ | || | _______ | |
| ||_ _||_ _|| || | / | | || ||_ \|_ _| | || | |_ ___ `. | || | |_ _||_ _| | || | / ___ | | |
| | | | /\ | | | || | `| | | || | | \ | | | || | | | `. \ | || | \ \ / / | || | | (__ \_| | |
| | | |/ \| | | || | | | | || | | |\ \| | | || | | | | | | || | \ \/ / | || | '.___`-. | |
| | | /\ | | || | _| |_ | || | _| |_\ |_ | || | _| |___.' / | || | _| |_ | || | |`\____) | | |
| | |__/ \__| | || | |_____| | || ||_____|\____| | || | |________.' | || | |______| | || | |_______.' | |
| | | || | | || | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
W1ndys的MD5加盐程序,首次发布:https://blog.w1ndys.top/
"""
)
input_string = input("请输入要加密的字符串: ")
hash_value, salt = md5_hash_with_salt(input_string)
print(f"输入字符串: {input_string}")
print(f"盐值: {salt.hex()}")
print(f"加盐前MD5哈希值: {hashlib.md5(input_string.encode('utf-8')).hexdigest()}")
print(f"加盐后MD5哈希值: {hash_value}")

运行结果

image-20240713161142588

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

.----------------. .----------------. .-----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| | _____ _____ | || | __ | || | ____ _____ | || | ________ | || | ____ ____ | || | _______ | |
| ||_ _||_ _|| || | / | | || ||_ \|_ _| | || | |_ ___ `. | || | |_ _||_ _| | || | / ___ | | |
| | | | /\ | | | || | `| | | || | | \ | | | || | | | `. \ | || | \ \ / / | || | | (__ \_| | |
| | | |/ \| | | || | | | | || | | |\ \| | | || | | | | | | || | \ \/ / | || | '.___`-. | |
| | | /\ | | || | _| |_ | || | _| |_\ |_ | || | _| |___.' / | || | _| |_ | || | |`\____) | | |
| | |__/ \__| | || | |_____| | || ||_____|\____| | || | |________.' | || | |______| | || | |_______.' | |
| | | || | | || | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
W1ndys的MD5加盐程序,首次发布:https://blog.w1ndys.top/

请输入要加密的字符串: W1ndys
输入字符串: W1ndys
盐值: 6fb286108beb8146011e4df7b779ba10
加盐前MD5哈希值: 4e9033367c1dcbf6df3b7ce889105a1d
加盐后MD5哈希值: 8627b18f8c5f5c018649f472ad7fa776

加盐前

image-20240713144436522

加盐后

image-20240713144450558