Skip to content

Commit db2c199

Browse files
authored
Merge pull request #168 from ikostan/main
Merge from master
2 parents 27d981f + 525096f commit db2c199

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
This is an implementation of the 'Atbash' cipher, an ancient
3+
encryption system created in the Middle East.
4+
"""
5+
6+
import string
7+
8+
alphabet: str = string.ascii_lowercase
9+
10+
11+
def encode(plain_text: str) -> str:
12+
temp_txt: [str] = [
13+
_replace(char) for char in plain_text if char not in ".,!? "
14+
]
15+
if len(temp_txt) > 4:
16+
step: int = 5
17+
i_start: int = 0
18+
i_end: int = i_start + step
19+
txt: list[str] = []
20+
while i_start <= len(temp_txt):
21+
tmp: str = "".join(temp_txt[i_start:i_end])
22+
if tmp:
23+
txt.append(tmp)
24+
i_start, i_end = i_end, i_end + step
25+
print(f"{' '.join(txt)}")
26+
return " ".join(txt)
27+
return "".join(temp_txt)
28+
29+
30+
def _replace(char: str) -> str:
31+
if char.lower().isalpha():
32+
new_indx: int = alphabet.index(char.lower()) + 1
33+
return alphabet[-new_indx]
34+
return char
35+
36+
37+
def decode(ciphered_text: str) -> str:
38+
return encode(ciphered_text).replace(" ", "")

0 commit comments

Comments
 (0)