Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
- NUMBER_CHARACTERS = len(chars)
- def encrypt(message, multiple):
- encrypted = ""
- substitute = []
- for i in range(NUMBER_CHARACTERS):
- idx = (i * multiple) % NUMBER_CHARACTERS
- substitute.append(chars[idx])
- for i in range(len(message)):
- char = message[i].lower()
- if char in chars:
- idx = chars.index(char)
- encrypted += substitute[idx]
- else:
- encrypted+= message[i]
- return encrypted
- def decrypt(message, multiple):
- decrypted = ""
- encrypted = ""
- substitute = []
- msg = encrypted
- msg = msg.lower()
- for letter in msg:
- if letter in substitute:
- idx = substitute.index(letter)
- decrypted += chars[idx]
- else:
- decrypted += letter
- return decrypted
- def main():
- choose = input("Would you like to encrypt or decrypt a message? ")
- if choose == "encrypt":
- text = input("Enter the message: ")
- multiple = int(input("Enter the multiple value: "))
- result = encrypt(text, multiple)
- print("Your encrypted message:" ,result)
- elif choose == "decrypt":
- text = input("Enter the message: ")
- multiple = int(input("Enter the multiple value: "))
- result = decrypt(text, multiple)
- print("Your decrypted message:" ,result)
- else:
- print("Invalid choice. Please enter 'encrypt' or 'decrypt'.")
- main()
Add Comment
Please, Sign In to add comment