Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: rot_all.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script presents users with a menu-driven interface for encrypting and decrypting text.
- It employs the ROT-n algorithm where 'n' represents the user-specified rotation value for text manipulation.
- Users can easily specify their desired rotation value and input text to perform encryption or decryption operations.
- Functions:
- - encrypt(text, rot): Encrypts the input text using the specified rotation value.
- - decrypt(text, rot): Decrypts the input text using the specified rotation value.
- - main(): Main function that displays the menu and handles user input.
- Requirements:
- - Python 3.x
- Usage:
- 1. Run the script.
- 2. Choose from the menu options:
- - Option 1: Encrypt - Input text and rotation value, then see the encrypted text.
- - Option 2: Decrypt - Input text and rotation value, then see the decrypted text.
- - Option 3: Exit - Quit the program.
- Example Output:
- ------------------------------
- :: Rot-All Menu ::
- 1. Encode
- 2. Decode
- 3. Exit
- Enter your choice: 1
- Enter text to encode: Jeoi Reqi
- Enter rotation value (1-25) or '26' for ALL: 22
- Encoded text:
- Fake Name
- ------------------------------
- :: Rot-All Menu ::
- 1. Encode
- 2. Decode
- 3. Exit
- Enter your choice: 2
- Enter text to decode: Fake Name
- Enter rotation value (1-25) or '26' for ALL: 22
- Decoded text:
- Jeoi Reqi
- ------------------------------
- :: Rot-All Menu ::
- 1. Encode
- 2. Decode
- 3. Exit
- Enter your choice: 2
- Enter text to decode: Fake Name
- Enter rotation value (1-25) or '26' for ALL: 26
- Decoded text:
- ROT-1: Gblf Obnf
- ROT-2: Hcmg Pcog
- ROT-3: Idnh Qdph
- ROT-4: Jeoi Reqi
- ROT-5: Kfpj Sfrj
- ROT-6: Lgqk Tgsk
- ROT-7: Mhrl Uhtl
- ROT-8: Nism Vium
- ROT-9: Ojtn Wjvn
- ROT-10: Pkuo Xkwo
- ROT-11: Qlvp Ylxp
- ROT-12: Rmwq Zmyq
- ROT-13: Snxr Anzr
- ROT-14: Toys Boas
- ROT-15: Upzt Cpbt
- ROT-16: Vqau Dqcu
- ROT-17: Wrbv Erdv
- ROT-18: Xscw Fsew
- ROT-19: Ytdx Gtfx
- ROT-20: Zuey Hugy
- ROT-21: Avfz Ivhz
- ROT-22: Bwga Jwia
- ROT-23: Cxhb Kxjb
- ROT-24: Dyic Lykc
- ROT-25: Ezjd Mzld
- ------------------------------
- :: Rot-All Menu ::
- 1. Encode
- 2. Decode
- 3. Exit
- Enter your choice: 3
- Exiting Program... GoodBye!
- ------------------------------
- Additional Notes:
- - The rotation value should be an integer between 1 and 25.
- - Encryption and decryption are case-sensitive.
- - Non-alphabetic characters remain unchanged during encryption/decryption.
- """
- def encrypt(text, rot):
- result = ''
- if rot == 26: # Encode with all ROT values
- for i in range(1, 26):
- result += f"\tROT-{i}:\t{encrypt(text, i)}\n"
- else:
- for char in text:
- if 'a' <= char <= 'z':
- result += chr((ord(char) - ord('a') + rot) % 26 + ord('a'))
- elif 'A' <= char <= 'Z':
- result += chr((ord(char) - ord('A') + rot) % 26 + ord('A'))
- else:
- result += char
- return result
- def decrypt(text, rot):
- result = ''
- if rot == 26: # Decode with all ROT values
- for i in range(1, 26):
- result += f"\tROT-{i}:\t{encrypt(text, i)}\n"
- else:
- for char in text:
- if 'a' <= char <= 'z':
- result += chr((ord(char) - ord('a') - rot) % 26 + ord('a'))
- elif 'A' <= char <= 'Z':
- result += chr((ord(char) - ord('A') - rot) % 26 + ord('A'))
- else:
- result += char
- return result
- def main():
- while True:
- print("-" * 30)
- print(":: Rot-All Menu ::\n")
- print("1. Encode")
- print("2. Decode")
- print("3. Exit")
- choice = input("\nEnter your choice: ")
- if choice == '1':
- text = input("\nEnter text to encode: ")
- rot = int(input("\nEnter rotation value (1-25) or '26' for ALL: "))
- print("\nEncoded text:\n\n", encrypt(text, rot))
- elif choice == '2':
- text = input("\nEnter text to decode: ")
- rot = int(input("\nEnter rotation value (1-25) or '26' for ALL: "))
- print("\nDecoded text:\n\n", decrypt(text, rot))
- elif choice == '3':
- print("\nExiting Program...\tGoodBye!\n\n")
- print("-" * 30)
- break
- else:
- print("\nInvalid choice! Please enter a valid option.\n")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement