Skip to content

Instantly share code, notes, and snippets.

@AgustinParmisano
Created November 16, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgustinParmisano/9fc2596212bbb2b5ec1d85271568d58c to your computer and use it in GitHub Desktop.
Save AgustinParmisano/9fc2596212bbb2b5ec1d85271568d58c to your computer and use it in GitHub Desktop.
cesar cipher with circular queue
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))
@ggoral
Copy link

ggoral commented Nov 20, 2018

Muyyyy bueno!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment