Created
November 16, 2018 17:54
-
-
Save AgustinParmisano/9fc2596212bbb2b5ec1d85271568d58c to your computer and use it in GitHub Desktop.
cesar cipher with circular queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
class ColaCircular: | |
def __init__(self): | |
self.datalist = [] | |
def push(self, data): | |
self.datalist.append(data) | |
def pop(self): | |
aux = self.datalist[0] | |
self.datalist.pop(0) | |
self.datalist.append(aux) | |
return aux | |
cc = ColaCircular() | |
class Cesar: | |
def __init__(self): | |
cc = ColaCircular() | |
for i in string.lowercase: | |
cc.push(i) | |
self.abcdario = cc | |
def reset_cc(self): | |
cc = ColaCircular() | |
for i in string.lowercase: | |
cc.push(i) | |
self.abcdario = cc | |
def cipher(self, msg, key): | |
result = "" | |
for i in msg: | |
for j in range(0, string.lowercase.index(i) + key +1): | |
c = self.abcdario.pop() | |
self.reset_cc() | |
result += c | |
return result | |
def decipher(self, msg, key): | |
result = "" | |
for i in msg: | |
for j in range(0, len(string.lowercase) + string.lowercase.index(i) - key +1): | |
c = self.abcdario.pop() | |
self.reset_cc() | |
result += c | |
return result | |
cesar = Cesar() | |
msg = raw_input("Ingrese mensaje a cifrar con Cesar: ") | |
key = input("Ingrese clave numerica para cifrado Cesar: ") | |
cipher_msg = cesar.cipher(msg,key) | |
print("Mensaje cifrado con Cesar: " + str(cipher_msg)) | |
decipher_msg= cesar.decipher(cipher_msg,key) | |
print("Mensaje descifrado con Cesar: " + str(decipher_msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muyyyy bueno!