Skip to main content
Post Closed as "Not suitable for this site" by Curt F., Mast, SuperBiasedMan, Barry, rolfl
fix indentation so the code actually runs
Source Link
alexwlchan
  • 8.7k
  • 1
  • 23
  • 55
#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.

#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.

#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.

the question is about caesar cipher, mention it in the title and add the tag
Link

Letter Altering Code (by Caesar cipher using the word length) in Pyhton as key

Source Link

Letter Altering Code (by word length) in Pyhton

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.

Thanks in advance for any help and/or advice.