-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcesarin.py
More file actions
29 lines (22 loc) · 743 Bytes
/
Copy pathcesarin.py
File metadata and controls
29 lines (22 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
alfabeto = "abcdefghijklmnñopqrstuvwxyz"
long = len(alfabeto)
def cesarin(texto, dezplazamiento):
resultado = ""
for c in texto:
if c.lower() in alfabeto:
es_mayuscula = c.isupper()
indice = alfabeto.index(c.lower())
nuevo_indice = (indice-dezplazamiento) % long
nueva_letra = alfabeto[nuevo_indice]
if es_mayuscula:
nueva_letra = nueva_letra.upper()
resultado += nueva_letra
else:
resultado += c
return resultado
def todas_las_formas(texto):
for shift in range(27):
print(f"Shift {shift:2d}: {cesarin(texto, shift)}")
if __name__ == "__main__":
texto = "cadena"
todas_las_formas(texto)