File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
solutions/python/atbash-cipher/1 Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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 (" " , "" )
You can’t perform that action at this time.
0 commit comments