mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-06 17:15:01 -06:00
atbash, robot simulator, sum of multiples exercises
This commit is contained in:
19
python/atbash-cipher/atbash_cipher.py
Normal file
19
python/atbash-cipher/atbash_cipher.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from string import ascii_letters, punctuation, whitespace
|
||||
|
||||
rev = ascii_letters[25::-1] + ascii_letters[:25:-1]
|
||||
enc = str.maketrans(ascii_letters, rev)
|
||||
dec = str.maketrans(rev, ascii_letters)
|
||||
san = str.maketrans('', '', punctuation)
|
||||
|
||||
def groupings(text, groupby=5):
|
||||
for i in range(0, len(text), groupby):
|
||||
yield text[i:i + groupby]
|
||||
|
||||
def sanitize(text):
|
||||
return ''.join(text.translate(san).split())
|
||||
|
||||
def encode(plain_text):
|
||||
return ' '.join(groupings(sanitize(plain_text.translate(enc).lower())))
|
||||
|
||||
def decode(ciphered_text):
|
||||
return ''.join(ciphered_text.translate(dec).lower().split())
|
||||
Reference in New Issue
Block a user