Reputation: 23
Working on a program that "encrypts" and "decrypts" an input string, no matter how I arrange my returns or function calls. I feel like something is stupidly out of place, but I'm at my wits end to have this actually do what it needs to. It'll go through the first input questions, then never executes the function I ask it to.
def DecryptMe(strEncryptedInput):
for key in range(1,101):
strDecrypt = strEncryptedInput
strDecryptedOutput = ''
for c in strDecrypt:
if (ord(c) - key < 32):
DecryptedInteger =((ord(c) - key) + 127 - 32)
strDecryptedOutput = strDecryptedOutput + chr(DecryptedInteger)
else:
DecryptedInteger = (ord(c) - key)
strDecryptedOutput = strDecryptedOutput + chr(DecryptedInteger)
print(key,"= ",strDecryptedOutput)
def EncryptMe(strDecryptedInput,key):
strEncrypt = strDecryptedInput
strEncryptedOutput = ''
for c in strEncrypt:
if (ord(c) - key < 32):
EncryptedInteger = ((ord(c) + key) - 127 + 32)
strEncryptedOutput = strEncryptedOutput + chr(EncryptedInteger)
else:
EncryptedInteger = (ord(c) + key)
strEncryptedOutput = strEncryptedOutput + chr(EncryptedInteger)
return strEncryptedOutput
strChoice = input("Please either chose to (E)ncrypt or (D)ecrypt a message.")
if strChoice == "e" or strChoice == "E":
strDecrypedInput = ""
strInput = input("Please type the string you wish to encrypt and press the Enter key.")
intKeyInput = int(input("Please enter a key from 1 to 100 to encrypt the message with."))
EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strDecryptedInput,"= ",strEncryptedOutput, " Key = ",key)
elif strChoice == "d" or strChoice =="D":
print("")
else:
print("")
#key = 88
#DecryptMe(":mmZ\dxZmx]Zpgy")
#EncryptMe(strDecryptedInput,key)
Mode()
Upvotes: 2
Views: 86
Reputation: 2016
you might try changing these two lines:
EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strDecryptedInput,"= ",strEncryptedOutput, " Key = ",key)
to this
strEncryptedOutput = EncryptMe(strDecryptedInput = strInput,key = intKeyInput)
print(strInput,"= ",strEncryptedOutput, " Key = ", str(intKeyInput))
I ran your code with these modifications (on Python 3.5.1) and the encryptor runs beautifully :)
Upvotes: 3