#Letter altering code
#This is to use string.ascii_lowercase which is a lowercase alphabet
import string
alphabet = string.ascii_lowercase
textIn= ""
trans = raw_input("Press 'e' to encrypt. \n Press 'd' to decrypt. \n press 'q' to quit.")
if trans.lower() == 'e':
while textIn.lower() != 'q':
textIn = raw_input("Type a sentence to be translated ('q' to quit).\n").lower()
textOut = ""
if textIn == 'q':
pass
else:
for word in textIn.split():
newWord = ""
for char in word:
if char in alphabet:
pos = alphabet.index(char)
newPos = (pos + len(word))%26
newChar = alphabet[newPos]
newWord += newChar
else:
newWord += char
textOut += newWord + " "
print(textOut)
elif trans.lower() == 'd':
while textIn.lower() != 'q':
textIn = raw_input("Type a sentence to be translated ('q' to quit).\n").lower()
textOut = ""
if textIn == 'q':
pass
else:
for word in textIn.split():
newWord = ""
for char in word:
if char in alphabet:
pos = alphabet.index(char)
newPos = (pos - len(word))%26
newChar = alphabet[newPos]
newWord += newChar
else:
newWord += char
textOut += newWord + " "
print(textOut)
elif trans.lower() == 'q':
pass
else:
print "Command not found. Please try again."
trans = raw_input("Press 'e' to encrypt. \n Press 'd' to decrypt. \n press 'q' to quit.")
It would also be nice to incorporate the ablitly import a txt document to be coded or decoded. For now I want to get this working.
Thanks in advance for any help and/or advice.