Nov-21-2020, 06:57 AM
Hi!
I’m learning about Caesar ciphers. I attempted to write my own from scratch some time ago which I only partially got working. I’m starting fresh, this time learning from sample code from Tutorials Point.
Here is their script with slight modifications that I have made:
Where each letter is shifted 1 character to the right.
However here is my actual output:
It appears only the first letter is shifted.
These are my questions for all of you:
I’m learning about Caesar ciphers. I attempted to write my own from scratch some time ago which I only partially got working. I’m starting fresh, this time learning from sample code from Tutorials Point.
Here is their script with slight modifications that I have made:
message = 'Hello' #encrypted message LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def encrypt(message, LETTERS): for key in range(len(LETTERS)): translated = '' for character in message: if character in LETTERS: num = LETTERS.find(character) num = num - key if num < 0: num = num + len(LETTERS) translated = translated + LETTERS[num] else: translated = translated + character return translated print(f"Encrypted message : {encrypt(message, LETTERS)}")Here is my expected output:
Quote:$ python script.py
Encrypted message : Ifmmp
Where each letter is shifted 1 character to the right.
However here is my actual output:
Quote:$ python script.py
Encrypted message : Iello
It appears only the first letter is shifted.
These are my questions for all of you:
- Why is only the first letter shifted when all the letters should be shifted?
- How might you people modify the algorithm to shift one character to the right?