Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Created May 28, 2012 19:47
Show Gist options
  • Save fforbeck/2820885 to your computer and use it in GitHub Desktop.
Save fforbeck/2820885 to your computer and use it in GitHub Desktop.
pc_01
def conv(x):
i = ord(x)
if i < 121:
return chr(i + 2)
elif i == 121:
return chr(ord('a'))
elif i == 122:
return chr(ord('b'))
alfabeto = list(x for x in 'abcdefghijklmnopqrstuvwxyz')
print("========= Alfabeto ==========")
print(alfabeto)
print("\n\n\n")
print("========= Mapa ===========")
_dict = {k : conv(k) for k in alfabeto}
for k, v in _dict.items():
print(k, v, sep=' -> ')
print("\n\n\n")
texto = """g fmnc wms bgblr rpylqjyrc gr zw fylb.
rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb
gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle.
sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."""
print("======== Texto original =========")
print(texto)
print("\n\n\n")
def switch(x):
if ord(x) < 99 or ord(x) > 122:
return x
else:
return _dict[x]
texto_final = ""
for letra in texto:
texto_final += str(switch(letra))
print("======== Texto traduzido =========")
a = "".join(alfabeto)
print(a)
b = "".join(list(x for x in _dict.values()))
print(b)
print(texto.translate(str.maketrans(a, b)))
#print(texto_final)
print("\n\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment