Advertisement
RapidR3D

Cipher(This is cool!)

Apr 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import time
  2.  
  3. MAX_KEY_SIZE = 26
  4.  
  5. getMessage = input("Enter the coded message: ").lower()
  6.  
  7.  
  8.  
  9.  
  10.  
  11. def translation():
  12.     key = 0
  13.     while True:
  14.         print('Enter the key number (1-%s)' % (MAX_KEY_SIZE))
  15.         key = int(input())
  16.         if (key >= 1 and key <= MAX_KEY_SIZE):
  17.             print("calculation in progress...")
  18.             time.sleep(3)
  19.            
  20.             while True:
  21.                 message = getMessage
  22.                 translated = ''
  23.                 for symbol in message:
  24.                     if symbol.isalpha():
  25.                         num = ord(symbol)
  26.                         num += key
  27.                         if symbol.islower():
  28.                             if num > ord('z'):
  29.                                 num -= 26
  30.                             elif num < ord('a'):
  31.                                 num += 26
  32.                         translated += chr(num)
  33.                     else:
  34.                         translated += symbol
  35.                    
  36.                    
  37.                 return translated
  38.         #return translated
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement