Advertisement
melvinSanGerman

Old Retro SMS texting

Jun 29th, 2024
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | Source Code | 0 0
  1. #!/usr/bin/python3
  2.  
  3. class retroSMS:
  4.     def __init__(self):
  5.         self.teclas = {0:[" ","0"], 1:["1"], 2:["a","b","c","2"], 3:["d","e","f","3"], 4:["g","h","i","4"], 5:["j","k","l","5"], 6:["m","n","o","6"], 7:["p","q","r","s","7"], 8:["t","u","v","8"], 9:["w","x","y","z","9"]}
  6.     def encode(self, texto):
  7.         self.code = ""
  8.         self.texto = texto.lower()  
  9.         for i in self.texto:
  10.             for key, lst in self.teclas.items():
  11.                 if i in lst:
  12.                    self.code += str(key)*(lst.index(i)+1) + " "
  13.     def decode(self, texto):
  14.         self.texto = texto.split(" ")
  15.         self.code = ""
  16.         for i in self.texto:
  17.             for key, lst in self.teclas.items():
  18.                 if int(i[-1]) == key:
  19.                     self.code += lst[len(i)-1]
  20.     def __str__(self):
  21.         return self.code    
  22. mensaje = input("Introduce un mensaje a codificar aquí: ")        
  23. cadena = retroSMS()
  24. cadena.encode(mensaje)
  25. print(str(cadena))
  26. cadena.decode(str(cadena).strip())
  27. print(str(cadena))
  28.  
  29. # Este código simulará la cantidad de veces que hay que presionar cada tecla para redactar el mensaje.
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement