I just wrote a program in Python. The program does what follows:
There is a class called original. It has 2 methods (a part of init). The first method is code. What "code" does is receive a string and encode it changing every character from the received string for another character of the ASCII table. This ASCII character depends of the function generacion_clave. The function generacion_clave generates randomly a number between 1 and k (k is an input parameter for this function).
For example the character "e" is in the place 101 on the ASCII table. So if the generated number is 8, the character e is changed for the character in the ASCII table which has the position 109 (101 + 8)
The method decode receives the encoded string and the clave, and it returns the decoded string.
What I would like to do is add to the program a graphic interface that contains:
An entry box for the original String, A Canvas (or a output box?) where the encoded and decoded string will we shown, a button to encode and a button to decode.
I am quite new in Python, I have read some tutorials about Tkinter but I don´t find it easy at all. So I would appreciate any help :)
from random import randint
class original():
def __init__(self, mensaje_original):
self.mensaje_original = mensaje_original
def code(self, gen_clav, *args):
cadena_codificada =""
clave = gen_clav(*args)
for i in self.mensaje_original:
clave_mod = ord(i) + clave
if clave_mod > 255:
clave_mod = clave_mod - 255
cadena_codificada = cadena_codificada + chr(clave_mod)
return cadena_codificada, clave
def decode(self, cadena_cod_clave):
cadena_decodificada =""
clave = int(cadena_cod_clave[1])
for i in cadena_cod_clave[0]:
clave_mod = ord(i) - clave
if clave_mod > 255:
clave_mod = clave_mod - 255
cadena_decodificada = cadena_decodificada + chr(clave_mod)
return cadena_decodificada, cadena_cod_clave[1]
def generacion_clave(k):
cl = randint(1, k + 1)
return cl
mensaje_original = "Hola tio como estas"
mensaje = original(mensaje_original)
cad_cod_clav = mensaje.code(generacion_clave, 10)
cad_dec_clav = mensaje.decode(cad_cod_clav)
print "La cadena original es: %s" %cad_dec_clav[0]
print "La cadena cifrada es: %s" %cad_cod_clav[0]
print "la clave es: %d " %cad_cod_clav[1]
Thanks a lot in advance! Pablo