Convert a number into its respective letter in the alphabet - Python 2.7 -


i working on python project take string of text, encrypt text adding keyword , outputting result. have features of program operational except converting numerical value text.

for example, raw text converted numerical value, instance [a, b, c] become [1, 2, 3].

currently have no ideas of how correct issue , welcome help, current code follows:

def encryption():     print("you have chosen encryption")     outputkeyword = []     output = []      input = raw_input('enter text: ')     input = input.lower()      character in input:         number = ord(character) - 96         output.append(number)      input = raw_input('enter keyword: ')     input = input.lower()     characterkeyword in input:         numberkeyword = ord(characterkeyword) - 96         outputkeyword.append(numberkeyword)         first = output         second = outputkeyword      print("the following debugging only")     print output     print outputkeyword      outputfinal = [x + y x, y in zip(first, second)]     print outputfinal  def decryption():     print("you have chosen decryption")     outputkeyword = []     output = []     input = raw_input('enter text: ')     input = input.lower()     character in input:         number = ord(character) - 96         output.append(number)      input = raw_input('enter keyword: ')     input = input.lower()     characterkeyword in input:         numberkeyword = ord(characterkeyword) - 96         outputkeyword.append(numberkeyword)         first = output         second = outputkeyword      print("the following debuging only")     print output     print outputkeyword      outputfinal = [y - x x, y in zip(second, first)]     print outputfinal  mode = raw_input("encrypt 'e' or decrypt 'd' ")  if mode == "e":     encryption() elif mode == "d":     decryption() else:     print("enter valid option")     mode = raw_input("encrypt 'e' or decrypt 'd' ")      if mode == "e":         encryption()     elif mode == "d":         decryption() 

although question not quite clear wrote script encryption using dictionary

plaintext = list('abcdefghijklmnopqrstuvwxyz') #alphabet string input etext = list('1a2b3c4d5e6f7g8h90ijklmnop') """here string combination of numbers , alphabets can replace kinda format , dictionary build respect alphabet sting"""                def messageenc(text,plain, encryp):   dictionary = dict(zip(plain, encryp))   newmessage = ''   char in text:     try:         newmessage = newmessage + dictionary[char.upper()]     except:         newmessage += ''  print(text,'has been encryptd to:',newmessage)  def messagedec(text,encryp, plain):  dictionary = dict(zip(encryp,plain))  newmessage = ''  char in text:     try:          newmessage = newmessage + dictionary[char.upper()]      except:         newmessage += ''  print(text,'has been decrypted to:',newmessage)   while true:  print("""    simple dictionary encryption :    press 1 encrypt    press 2 decrypt    """)   try:      choose = int(input())   except:      print("press either 1 or 2")      continue    if choose == 1:      text = str(input("enter something: "))     messageenc(text,plaintext,etext)     continue   else:     text = str(input("enter something: "))     messagedec(text,etext,plaintext) 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -