-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.py
More file actions
31 lines (19 loc) · 787 Bytes
/
Copy pathpassword.py
File metadata and controls
31 lines (19 loc) · 787 Bytes
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
def encrypt(key, password):
encrypted = []
for letter in password:
encrypted.append(ord(letter) * key)
for i in range(len(encrypted) - 1):
encrypted[i] = (encrypted[i] + encrypted[i + 1]) / 2
encrypted[-1] = encrypted[-1]
return ','.join(str(x) for x in encrypted)
def decrypt(key, encrypted):
decrypted = list(encrypted.split(','))
password = ''
for i in range(len(decrypted)):
decrypted[i] = float(decrypted[i])
for i in range(len(decrypted) - 1):
decrypted[len(decrypted) - 2 - i] = decrypted[len(decrypted) - 2 - i] * 2 - decrypted[len(decrypted) - 1 - i]
for i in range(len(decrypted)):
decrypted[i] = int(decrypted[i] / key)
password += (chr(decrypted[i]))
return password