Advertisement
g-stoyanov

CesarEncryption

Feb 12th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from string import ascii_uppercase, ascii_lowercase
  2.  
  3. try:
  4.     k = int(input())
  5.     inputStr = input()
  6.     result = ""
  7.  
  8.     for i in range(0, len(inputStr)):
  9.         if ord(inputStr[i]) > 64 and ord(inputStr[i]) < 92:
  10.             encryptedPos = (ord(inputStr[i]) - 65) + k
  11.             encryptedIndex = encryptedPos if encryptedPos < len(ascii_uppercase) else encryptedPos - len(ascii_uppercase)
  12.             result += ascii_uppercase[encryptedIndex]
  13.         elif inputStr[i] in ascii_lowercase:
  14.             result = "INVALID INPUT"
  15.             break
  16.         else:
  17.             result += inputStr[i]
  18.  
  19.     print(result)
  20.    
  21. except:
  22.     print("INVALID INPUT")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement