SHARE
TWEET

CesarEncryption

g-stoyanov Feb 12th, 2016 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top