DanielHannon

Encryptor

May 15th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. """ENCRYPTOR TEST"""
  2. def key():
  3.     a = True
  4.     inp = int(raw_input("please enter a key: "))
  5.     if inp <= 35:
  6.         return inp
  7.     else:
  8.         while a == True:
  9.             inp = int(raw_input("please enter a key: "))
  10.             if inp <= 35:
  11.                     a = False
  12.     return inp
  13.            
  14. def encrypt(eord):
  15.     output = ""
  16.     alphabet = ["7","a","0","b","c","5","d","e","6","f","g","1","h","i","j","k","8","l","3","m","n","2","o","p","q","9","r","4","s","t","u","v","w","x","y","z"]
  17.     inp = raw_input("What phrase would you like to Change?: ")
  18.     key1 = key()
  19.     phrase = inp.split()
  20.     for i in phrase:
  21.         i = i.lower()
  22.         splitword  = list(i)
  23.         for a in range(len(splitword)):
  24.             for c in range(35):
  25.                 if splitword[a] == alphabet[c]:
  26.                     if eord == 1: #if you chose to encrypt
  27.                         letter = c + key1 #the new position is created by adding the key to the position of the letter in the alphabet
  28.                     elif eord == 0: # if you chose to decrypt
  29.                         letter = c - key1 # the actual position of the letter is determined
  30.                     #out of bounds checks
  31.                     if letter > 35:
  32.                         letter = letter - 35
  33.                     elif letter < 0:
  34.                         letter = 35 + letter
  35.                     output += str(alphabet[letter]) #appends newly generated encryption/decryption to the overall output
  36.  
  37.    
  38.     print output # does what it says on the tin
  39.  
  40. print("Welcome to encryption service v0.1")
  41. resp1= raw_input("Would you like to encrypt or decrypt: ")
  42. resp1 = resp1.lower()
  43. if resp1 == "encrypt" or resp1 == "e":
  44.     encrypt(1)
  45. elif resp1 == "decrypt" or resp1 == "d":
  46.     encrypt(0)
Advertisement
Add Comment
Please, Sign In to add comment