Cypher Shift
Intro Video
Intro Video
Example Program
Example Program
'''
This program encrypts uppercase characters by shifting them two the right. A becomes C, B becomes D, etc.
Note the use of modulo to handle the end of the alphabet, i.e., Y becomes A, Z becomes B
'''
import string
# number of characters to shift over
shift = 2
# print the string being encrypted
print(string.ascii_uppercase)
# print each shifted character
for letter in string.ascii_uppercase:
print(chr((ord(letter) - 65 + shift) % 26 + 65), end='')
Questions
Questions
Why have we subtracted 65 from the ordinal value of each character?
Why have used modulo 26?
Assignment 1
Assignment 1
Modify the program above to work exclusively with lowercase letters.
Assignment 2
Assignment 2
Modify the program(s) above to work with both upper- and lowercase letters.