-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (30 loc) · 1.13 KB
/
main.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
import hashlib
def generate_salt(text):
# Generate salt from input
hashed_text = hashlib.sha256(text.encode()).hexdigest()
return hashed_text
def mix_salt_into_password(password, salt):
# Mix salt with password using XOR operation
password_bytes = password.encode()
salt_bytes = salt.encode()
max_len = max(len(password_bytes), len(salt_bytes))
mixed_password = bytearray(max_len)
for i in range(max_len):
mixed_password[i] = password_bytes[i % len(password_bytes)] ^ salt_bytes[i % len(salt_bytes)]
return mixed_password.hex()
def hash_password(password):
# Hash password
hashed_password = hashlib.sha256(password.encode()).hexdigest()
return hashed_password
# Get password input
password = input("Enter a password: ")
# Generate salt
salt = generate_salt(password)
# Mix salt with password and hash the password
mixed_password = mix_salt_into_password(password, salt)
hashed_password = hash_password(mixed_password)
#Print results
print(f"Password: {password}")
print(f"Salt: {salt}")
print(f"Mixed Password: {mixed_password}")
print(f"Hashed Password: {hashed_password}")