primeiro commit com exercicios de Exercism realizados até esta data
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
def encode(plain_text: str) -> str:
|
||||
encoded_text: str = ""
|
||||
weight: int = 0
|
||||
for char in plain_text.lower():
|
||||
if char.isalpha():
|
||||
encoded_text += chr(97 + 25 - (ord(char) - 97))
|
||||
weight += 1
|
||||
elif char.isdigit():
|
||||
encoded_text += char
|
||||
weight += 1
|
||||
else:
|
||||
continue
|
||||
if (weight % 5) == 0:
|
||||
encoded_text += " "
|
||||
# remove space at the end when it exists
|
||||
if encoded_text[-1] == " ":
|
||||
return encoded_text[0:-1]
|
||||
return encoded_text
|
||||
|
||||
|
||||
def decode(ciphered_text: str) -> str:
|
||||
decoded_text: str = ""
|
||||
for char in ciphered_text.lower():
|
||||
if char.isalpha():
|
||||
decoded_text += chr(122 - 25 + (122 - ord(char)))
|
||||
elif char.isdigit():
|
||||
decoded_text += char
|
||||
else:
|
||||
continue
|
||||
return decoded_text
|
||||
Reference in New Issue
Block a user