Underc0de

Programación Scripting => Python => Mensaje iniciado por: Sanko en Febrero 13, 2014, 12:48:47 PM

Título: Cifrado solitario
Publicado por: Sanko en Febrero 13, 2014, 12:48:47 PM
Código (python) [Seleccionar]
import string
xAbc = string.ascii_lowercase + '-'

def solitario(texto, ristra, opt):
    nText = [xAbc.find(x) + 1 for x in texto.lower()]
    nRistra = [xAbc.find(x) + 1 for x in ristra.lower()]
   
    if opt == 1:
        print "".join([xAbc[x - 1].replace('-', ' ') for x in [(nText[x] + nRistra[x]) % 26 for x in range(len(texto))]])

    elif opt == 0:
        print "".join([xAbc[x - 1].replace('-', ' ') for x in [(nText[x] - nRistra[x]) % 26 for x in range(len(texto))]])
       
#encoded output -> oexwa khqtw
#decoded output -> donot usepc