Python Forum
Password Encryption Help Python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Encryption Help Python3
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.

def caesar(text):
    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))
    return ciphertext
text = input("Enter a password: ")
print('Plain Text: ', text)
print('Cipher:', caesar(text))
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
Skaperen likes this post
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020