Advertisement
Python253

rot_all

May 5th, 2024
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: rot_all.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script presents users with a menu-driven interface for encrypting and decrypting text.
  9. It employs the ROT-n algorithm where 'n' represents the user-specified rotation value for text manipulation.
  10. Users can easily specify their desired rotation value and input text to perform encryption or decryption operations.
  11.  
  12. Functions:
  13.    - encrypt(text, rot): Encrypts the input text using the specified rotation value.
  14.    - decrypt(text, rot): Decrypts the input text using the specified rotation value.
  15.    - main(): Main function that displays the menu and handles user input.
  16.  
  17. Requirements:
  18.    - Python 3.x
  19.  
  20. Usage:
  21.    1. Run the script.
  22.    2. Choose from the menu options:
  23.       - Option 1: Encrypt - Input text and rotation value, then see the encrypted text.
  24.       - Option 2: Decrypt - Input text and rotation value, then see the decrypted text.
  25.       - Option 3: Exit - Quit the program.
  26.  
  27. Example Output:
  28.  
  29.    ------------------------------
  30.    :: Rot-All Menu ::
  31.  
  32.    1. Encode
  33.    2. Decode
  34.    3. Exit
  35.  
  36.    Enter your choice: 1
  37.  
  38.    Enter text to encode: Jeoi Reqi
  39.  
  40.    Enter rotation value (1-25) or '26' for ALL: 22
  41.  
  42.    Encoded text:
  43.  
  44.     Fake Name
  45.    ------------------------------
  46.    :: Rot-All Menu ::
  47.  
  48.    1. Encode
  49.    2. Decode
  50.    3. Exit
  51.  
  52.    Enter your choice: 2
  53.  
  54.    Enter text to decode: Fake Name
  55.  
  56.    Enter rotation value (1-25) or '26' for ALL: 22
  57.  
  58.    Decoded text:
  59.  
  60.     Jeoi Reqi
  61.    ------------------------------
  62.    :: Rot-All Menu ::
  63.  
  64.    1. Encode
  65.    2. Decode
  66.    3. Exit
  67.  
  68.    Enter your choice: 2
  69.  
  70.    Enter text to decode: Fake Name
  71.  
  72.    Enter rotation value (1-25) or '26' for ALL: 26
  73.  
  74.    Decoded text:
  75.  
  76.        ROT-1:   Gblf Obnf
  77.        ROT-2:   Hcmg Pcog
  78.        ROT-3:   Idnh Qdph
  79.        ROT-4:   Jeoi Reqi
  80.        ROT-5:   Kfpj Sfrj
  81.        ROT-6:   Lgqk Tgsk
  82.        ROT-7:   Mhrl Uhtl
  83.        ROT-8:   Nism Vium
  84.        ROT-9:   Ojtn Wjvn
  85.        ROT-10:  Pkuo Xkwo
  86.        ROT-11:  Qlvp Ylxp
  87.        ROT-12:  Rmwq Zmyq
  88.        ROT-13:  Snxr Anzr
  89.        ROT-14:  Toys Boas
  90.        ROT-15:  Upzt Cpbt
  91.        ROT-16:  Vqau Dqcu
  92.        ROT-17:  Wrbv Erdv
  93.        ROT-18:  Xscw Fsew
  94.        ROT-19:  Ytdx Gtfx
  95.        ROT-20:  Zuey Hugy
  96.        ROT-21:  Avfz Ivhz
  97.        ROT-22:  Bwga Jwia
  98.        ROT-23:  Cxhb Kxjb
  99.        ROT-24:  Dyic Lykc
  100.        ROT-25:  Ezjd Mzld
  101.  
  102.    ------------------------------
  103.    :: Rot-All Menu ::
  104.  
  105.    1. Encode
  106.    2. Decode
  107.    3. Exit
  108.  
  109.    Enter your choice: 3
  110.  
  111.    Exiting Program...  GoodBye!
  112.  
  113.  
  114.    ------------------------------
  115.    
  116. Additional Notes:
  117.    - The rotation value should be an integer between 1 and 25.
  118.    - Encryption and decryption are case-sensitive.
  119.    - Non-alphabetic characters remain unchanged during encryption/decryption.
  120. """
  121.  
  122. def encrypt(text, rot):
  123.     result = ''
  124.     if rot == 26:  # Encode with all ROT values
  125.         for i in range(1, 26):
  126.             result += f"\tROT-{i}:\t{encrypt(text, i)}\n"
  127.     else:
  128.         for char in text:
  129.             if 'a' <= char <= 'z':
  130.                 result += chr((ord(char) - ord('a') + rot) % 26 + ord('a'))
  131.             elif 'A' <= char <= 'Z':
  132.                 result += chr((ord(char) - ord('A') + rot) % 26 + ord('A'))
  133.             else:
  134.                 result += char
  135.     return result
  136.  
  137.  
  138. def decrypt(text, rot):
  139.     result = ''
  140.     if rot == 26:  # Decode with all ROT values
  141.         for i in range(1, 26):
  142.             result += f"\tROT-{i}:\t{encrypt(text, i)}\n"
  143.     else:
  144.         for char in text:
  145.             if 'a' <= char <= 'z':
  146.                 result += chr((ord(char) - ord('a') - rot) % 26 + ord('a'))
  147.             elif 'A' <= char <= 'Z':
  148.                 result += chr((ord(char) - ord('A') - rot) % 26 + ord('A'))
  149.             else:
  150.                 result += char
  151.     return result
  152.  
  153.  
  154. def main():
  155.     while True:
  156.         print("-" * 30)
  157.         print(":: Rot-All Menu ::\n")
  158.         print("1. Encode")
  159.         print("2. Decode")
  160.         print("3. Exit")
  161.        
  162.         choice = input("\nEnter your choice: ")
  163.  
  164.         if choice == '1':
  165.             text = input("\nEnter text to encode: ")
  166.             rot = int(input("\nEnter rotation value (1-25) or '26' for ALL: "))
  167.             print("\nEncoded text:\n\n", encrypt(text, rot))
  168.         elif choice == '2':
  169.             text = input("\nEnter text to decode: ")
  170.             rot = int(input("\nEnter rotation value (1-25) or '26' for ALL: "))
  171.             print("\nDecoded text:\n\n", decrypt(text, rot))
  172.         elif choice == '3':
  173.             print("\nExiting Program...\tGoodBye!\n\n")
  174.             print("-" * 30)
  175.             break
  176.         else:
  177.             print("\nInvalid choice! Please enter a valid option.\n")
  178.  
  179. if __name__ == "__main__":
  180.     main()
  181.  
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement