-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cipher.py
More file actions
39 lines (35 loc) · 996 Bytes
/
Copy pathcaesar_cipher.py
File metadata and controls
39 lines (35 loc) · 996 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
30
31
32
33
34
35
36
37
38
39
alfabeto=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","ñ","o","p","q","r","s","t","u","v","w","x","y","z"]
def posicion(letra,key,tipo):
posicion=0
nletra = letra
if tipo == "C":
for i in alfabeto:
if letra == i:
posicion+=key
while posicion>26:
posicion-=26
nletra = alfabeto[posicion]
posicion+=1
if tipo == "D":
for i in alfabeto:
if letra == i:
posicion-=key
while posicion<0:
posicion+=26
nletra = alfabeto[posicion]
posicion+=1
return nletra
try:
tipo=input("Cifrado Cesar:\n\t(C) Codificar\n\t(D) Decodificar\nOpcion: ")
text = input("\nIngresa el mensaje: ").lower()
key = int(input("Clave(Numero Entero): "))
if tipo == "C" or tipo == "D":
tam=len(text)
ntext = ""
for i in range(tam):
ntext += posicion(text[i],key,tipo)
print(f"\nMensaje: {ntext}")
else:
print("\nOpción erronea!")
except:
print("\nError en datos!")