Here is a code I'm working on that alters a individual letters.Each letter is pumped up x amount of letters. This alteration is dependent on the length of the word.
So for instance "hi" becomes "jk", "there" becomes "ymjwj", and thus "hi there" is "jk ymjwj".
I want to this code to not encrypt put to also decrypt messages. So the user could translate, "jk ymjwj" back to hi there using this formula.
Right now when the code is ran in terminal it produces indentation errors. I am still a python newbie so I'm uncertain how to fix these specific issues.`
#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.
<SPACE>print(textOut)toprint(textOut), if you fix that trivial error, we may review your code \$\endgroup\$