-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encrypt&DecryptYourNameWithPython.py
67 lines (57 loc) · 1.91 KB
/
Encrypt&DecryptYourNameWithPython.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
# Encrypt and Decrypt a Name using a combination of the Joints of the Alphabet
def encrypt(name):
"""
Encrypt a name using the Joints of the Alphabet
:param name: a string
:return: a string
"""
# Initialize the Joints of the Alphabet
alphabet = "abcdefghijklmnopqrstuvwxyz"
# Initialize the Joints of the Cipher
cipher = "zyxwvutsrqponmlkjihgfedcba"
# Initialize the encrypted name
encrypted_name = ""
# Loop through the name
for letter in name:
# Find the index of the letter in the alphabet
index = alphabet.find(letter)
# Add the cipher letter to the encrypted name
encrypted_name += cipher[index]
# Return the encrypted name
return encrypted_name
def decrypt(name):
"""
Decrypt an encrypted name using the Joints of the Alphabet
:param name: a string
:return: a string
"""
# Initialize the Joints of the Alphabet
alphabet = "abcdefghijklmnopqrstuvwxyz"
# Initialize the Joints of the Cipher
cipher = "zyxwvutsrqponmlkjihgfedcba"
# Initialize the decrypted name
decrypted_name = ""
# Loop through the name
for letter in name:
# Find the index of the letter in the cipher
index = cipher.find(letter)
# Add the alphabet letter to the decrypted name
decrypted_name += alphabet[index]
# Return the decrypted name
return decrypted_name
def main():
"""
Test the encrypt and decrypt functions
"""
# Get the name to encrypt
name = input("Enter a name to encrypt: ")
# Encrypt the name
encrypted_name = encrypt(name)
# Print the encrypted name
print("Encrypted name:", encrypted_name)
# Decrypt the name
decrypted_name = decrypt(encrypted_name)
# Print the decrypted name
print("Decrypted name:", decrypted_name)
# Call the main function
main()