Password Encryption Help Python3 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Password Encryption Help Python3 (/thread-30277.html) |
Password Encryption Help Python3 - SockMankey - Oct-13-2020 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. 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: RE: Password Encryption Help Python3 - DPaul - Oct-14-2020 You have a calulation method that works for upper and lowercase; For digits you do something different. Maybe you should use the same method, but not with 26 . Paul RE: Password Encryption Help Python3 - perfringo - Oct-14-2020 Another approach could be using constants provided by built-in string module (including ascii upper and lowercases and digits). Combining these constants with % for indices one should achieve desired result. |