Oct-13-2020, 04:28 PM
(This post was last modified: Oct-13-2020, 04:28 PM by SockMankey.)
I am trying to make a program that is given a password and encrypts it by shifting each value up by 3. For example, if you entered in the password: Ab1 you would get De4. I'm trying to make it to where if the input is Z or 9, the output loops back to the start. So the password for Z9 would be C3.
I know I need to have a loop in order to accomplish this, but I'm not sure which type of loop/where to put the loop.
I know I need to have a loop in order to accomplish this, but I'm not sure which type of loop/where to put the loop.
Quote:
def caesar(text): ciphertext="" for char in text: if char.isupper(): ciphertext += chr((ord(char)+3 -65)%+26+65) elif char.islower(): ciphertext += chr((ord(char)+3-97)%26+97) elif char.isdigit(): ciphertext += chr((ord(char)+3)) else: ciphertext+=char return ciphertext text = input("Enter a password: ") print('Plain Text: ', text) print('Cipher:', caesar(text))
Quote: