-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar_number.py
61 lines (52 loc) · 2.17 KB
/
caesar_number.py
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
51
52
53
54
55
56
57
58
59
60
61
import string
# @TODO: Create a function that print % of each character in sentence
def print_percentage(sentence: str):
sentence = list(sentence)
letters = []
punctuation = []
whitespace = []
for character in sentence:
if character in string.ascii_letters:
if character in letters:
continue
else:
letters.append(character)
print(character, string.ascii_letters.count(character) / len(sentence) * 100, "%")
elif character in string.punctuation:
if character in punctuation:
continue
else:
punctuation.append(character)
print(character, string.punctuation.count(character) / len(sentence) * 100, "%")
elif character == " ":
whitespace.append(character)
print(character, string.whitespace.count(character) / len(sentence) * 100, "%")
print("Done")
def decrypt_sentence(sentence: str, key: int):
sentence_decrypted = []
sentence.lower()
sentence = list(sentence)
for character in sentence:
if character in string.ascii_letters:
character = string.ascii_letters[(string.ascii_letters.index(character) + key + 1) % 26]
sentence_decrypted.append(character)
elif character in string.punctuation:
sentence_decrypted.append(character)
elif character == " ":
sentence_decrypted.append(character)
sentence_decrypted = ''.join(str(e) for e in sentence_decrypted)
print(sentence_decrypted)
def encrypt_sentence(sentence: str, key: int):
sentence_encrypted = []
sentence.lower()
sentence = list(sentence)
for character in sentence:
if character in string.ascii_letters:
character = string.ascii_letters[(string.ascii_letters.index(character) - key - 1) % 26]
sentence_encrypted.append(character)
elif character in string.punctuation:
sentence_encrypted.append(character)
elif character == " ":
sentence_encrypted.append(character)
sentence_encrypted = ''.join(str(e) for e in sentence_encrypted)
print(sentence_encrypted)