[Tutor] syntax error help
Awais Mamoon
awais.mamoon at live.com
Fri Aug 26 11:54:53 EDT 2016
Hi my code should be working however keeps coming up with invalid syntax but
I know there isnt one. Please help me its been 2 hours
Here is my code:
alphabet = 'abcdefghijklmnaopqrstuvwxyz'
#gets the message from the user so it can Encrypt or Decrypt
def getMessage():
print('Enter your message:')
return input()
#gets the key from the use so it can Encrypt or Decrypt the chosen message
def getKey():
while True:
print("please enter your keyword")
Keyword = input()
valid_Keyword = True
for letter in Keyword:
if (letter not in alphabet) and (letter != " "):
valid_Keyword = False
if valid_Keyword == False:
print("you need to enter a valid keyword")
if valid_Keyword == True:
return Keyword
def EncryptionOrDecryption(plaintext_message, Keyword):
NewLetter = ("")
Ciphertext = ("")
PositionKeyword = 0
print('Do you wish to encrypt or decrypt')
option = input()
if option == "e" or "encrypt":
for i in plaintext_message:
if i == "":
Ciphertext = Ciphertext + ""
else:
NewLetter = (alphabet.index(i)+1) +
alphabet.index(Keyword[PositionKeyword]
PositionKeyword = PositionKeyword + 1
if PositionKeyword == len(Keyword):
PositionKeyword = 0
if NewLetter > 25:
NewLetter = NewLetter - 26
Ciphertext = Ciphertext + alphabet[NewLetter]
return Ciphertext
elif option == "d" or "decrypt":
for i in plaintext_message:
if i == "":
Ciphertext = Ciphertext + ""
else:
NewLetter = (alphabet.index(i)-1) +
alphabet.index(Keyword[PositionKeyword])
PositionKeyword = Keyword + 1
if PositionKeyword == len(Keyword):
PositionKeyword = 0
if NewLetter > 25:
NewLetter = NewLetter - 26
Ciphertext = Ciphertext + alphabet[NewLetter]
return Ciphertext
#this makes the code abit more efficient
plaintext_message = getMessage()
Keyword = getKey()
Ciphertext = EncryptionOrDecryption(plaintext_message, Keyword)
#displays the Encyrpted/Decrypted message to the user
print('Your translated text is:')
print(Ciphertext)
More information about the Tutor
mailing list