-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshrift_code.py
More file actions
50 lines (50 loc) · 1.46 KB
/
Copy pathshrift_code.py
File metadata and controls
50 lines (50 loc) · 1.46 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
39
40
41
42
43
44
45
46
47
48
49
50
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"," "]
def get_data():
word = input('Enter your message: ').lower()
num = int(input('Enter a number (1-16): '))
while num > 26 or num == 0:
num = int(input('Out of range, Enter a number (1-16): '))
data = (word, num)
return data
def make_code(word, num):
new_word = ""
for i in word:
j = alphabet.index(i)
j += num
if j > 26:
j = j - 27
char = alphabet[j]
new_word = new_word + char
print(f'shifr_code {word} -> {new_word}')
print()
def decode(word, num):
new_word = ""
for i in word:
j = alphabet.index(i)
j -= num
if j < 0:
j = j + 27
char = alphabet[j]
new_word = new_word + char
print(f'shifr_decode {word} -> {new_word}')
print()
def main():
isAgain = True
while isAgain:
print('1) Make a code')
print('2) Decode a message')
print('3) Quit')
selection = input('Enter your selection: ')
if selection == '1':
(word, num) = get_data()
make_code(word, num)
elif selection =='2':
(word, num) = get_data()
decode(word, num)
elif selection == '3':
isAgain = False
else:
raise TypeError('your selection uncnown. Try again!')
if __name__ == '__main__':
main()