Skip to content

Commit

Permalink
Reto mouredev#24 - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoatrs committed Sep 23, 2023
1 parent 6f8b11e commit 626036b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/python/marcoatrs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from string import ascii_letters

def normal_a_cesar(texto: str, desplazamiento: int) -> str:
cifrado = []
for t in texto:
if t not in ascii_letters:
cifrado.append(t)
continue
limits = (65, 90) if t == t.capitalize() else (97, 122)
num = (ord(t) + desplazamiento)
if num > limits[1]:
num = (num - limits[1] + 1) + limits[0]
cifrado.append(chr(num))
return "".join(cifrado)


def cesar_a_normal(texto: str, desplazamiento: int):
normal = []
for t in texto:
if t not in ascii_letters:
normal.append(t)
continue
limits = (65, 90) if t == t.capitalize() else (97, 122)
num = (ord(t) - desplazamiento)
if num < limits[0]:
num = limits[1] - limits[0] - num
normal.append(chr(num))
return "".join(normal)


print(normal_a_cesar("Hola, no me entiendes muajaja!", 3))
print(cesar_a_normal(normal_a_cesar("Hola, no me entiendes muajaja!", 3), 3))

0 comments on commit 626036b

Please sign in to comment.