-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesar_Cipher_Part_One
More file actions
38 lines (26 loc) · 1.35 KB
/
Caesar_Cipher_Part_One
File metadata and controls
38 lines (26 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n").lower()
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
original_text = list(text)
new_text = []
# TODO-1: Create a function called 'encrypt()' that takes 'original_text' and 'shift_amount' as 2 inputs.
# def encrypt(original_text, shift_amount):
# for letters in original_text:
#
# my idea is to use append to add the new letters to a string.
def encrypt(original_text, shift):
new_text = []
for letters in original_text:
if alphabet.index(letters) + shift > 25:
new_text.append(alphabet[alphabet.index(letters) + (shift - 26)])
else:
new_text.append(alphabet[alphabet.index(letters) + shift])
new_text = ''.join(new_text)
print(new_text)
encrypt(original_text, shift)
# TODO-2: Inside the 'encrypt()' function, shift each letter of the 'original_text' forwards in the alphabet
# by the shift amount and print the encrypted text.
# TODO-4: What happens if you try to shift z forwards by 9? Can you fix the code?
# TODO-3: Call the 'encrypt()' function and pass in the user inputs. You should be able to test the code and encrypt a
# message.