Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf8 -*-
- #######################
- #Encode/Decoder
- #Criptografia por Transpocision geometrica
- #by
- #TrackMaze Hacking Group
- #######################
- #Trackmaze.blogspot.com
- #TrackMaze@gmail.com
- #######################
- #Marzo de 2013
- #######################
- def Create_matriz(mensaje,columnas,opcion): #tenemos dos maneras de crear la matriz, ya se horizontal o vertical (filas - columnas)
- matriz=[]
- mensaje=mensaje.replace(" ","")
- if (len(mensaje)%columnas!=0): #verificamos si la division es exacta
- mensaje=mensaje+"x"*(columnas-(len(mensaje)%columnas)) #rellenamos con x, las columnas faltantes
- i=len(mensaje)/columnas #obtenemos el numero de filas
- if (opcion=="horizontal"): #primera forma, la horizontal (por filas)
- for x in range (0,i): #recorremos las filas
- fila=[] #aqui almacenaremos as columnas
- for y in range(0,columnas): #recorremos las columnas
- fila.append(mensaje[y]) #agregamos cada caracter a la fila
- mensaje=mensaje[columnas:] #recortamos el mensaje hasta el numero de columnas que hayamos creado
- matriz.append(fila) #agregamos la fila a la matriz final
- return matriz #retornamos la matriz final
- else: #segunda forma, la vertical (por columnas)
- for h in range(0,i): #primero creamos las filas
- matriz.append([])
- for y in range (0,columnas): #recorremos las columnas
- for x in range(0,i): #recorremos las filas
- matriz[x].append(mensaje[x]) #a cada fila x la agregamos el caracter x del mensaje
- mensaje=mensaje[i:] #recortamos el mensaje hasta las filas que hayamos utilizado
- return matriz #retornamos la matriz final
- def lectura(opcion,matriz): #las dos posibles maneras de leer la matriz final, de forma horizontal o vertical
- n_fila=len(matriz) #cantidad de filas
- n_columnas=len(matriz[0]) #cantidad de columnas
- texto="" #texto final
- if (opcion=="horizontal"): #leemos de forma horizontal, por filas
- for i in range(0,n_fila): #recorremos las filas
- for j in range(0,n_columnas): #recorremos las columnas
- texto+=matriz[i][j] #almacenamos los valores, la fila se mantiene y la columna varia
- texto+=" " #al terminar una fila, dejamos un espacio
- return texto #retornamos el texto final
- else: #leemos de forma vertical, por columnas
- for j in range(0,n_columnas): #recorremos las columnas
- for i in range (0,n_fila): #recorremos las filas
- texto+=matriz[i][j] #almacenamos los valores, la columna se mantiene y la fila varia
- texto+=" " #despues de cada columna, se deja un espacio
- #print texto
- return texto #retornamos el texto final
- def cifrado_clave(matriz,clave):
- n_fila=len(matriz) #cantidad de filas
- n_columnas=len(matriz[0]) #cantidad de columnas
- texto="" #texto final
- new=[]
- for i in range(0,len(clave)):
- new.append(clave.index(str(i+1)))
- for y in new:
- for x in range (0,n_fila):
- texto+=matriz[x][int(y)]
- texto+=" "
- return texto
- def lectura_clave(matriz,clave): #esta sera la funcion que descifre el mensaje con una clave determinada
- n_fila=len(matriz) #cantidad de filas
- n_columnas=len(matriz[0]) #cantidad de columnas
- texto="" #texto final
- #teniendo la clave de descifrado, leemos de nuevo la matriz pero en dicho orden
- for i in range (0,n_fila): #recorremos las filas
- for x in clave: #recorremos el orden de las claves
- texto+=matriz[i][int(x)-1] #guardamos el texto
- texto+=" "
- return texto #retornamos el texto
- print """ _______ _ _
- |__ __| (_) (_)
- | |_ __ __ _ _ __ ___ _ __ ___ ___ _ ___ _ ___ _ __
- | | '__/ _` | '_ \/ __| '_ \ / _ \/ __| |/ __| |/ _ \| '_ \
- | | | | (_| | | | \__ | |_) | (_) \__ | | (__| | (_) | | | |
- _____| \__,_|_| |_|___| .__/ \___/|___|__\___|_|\___/|_| |_|
- / ____| | | | | (_)TrackMaze.blogspot.com
- | | __ ___ ___ _ __ ___| ___| |_ _ __ _ ___ __ _
- | | |_ |/ _ \/ _ \| '_ ` _ \ / _ | __| '__| |/ __/ _` |
- | |__| | __| (_) | | | | | | __| |_| | | | (_| (_| |
- \_____|\___|\___/|_| |_| |_|\___|\__|_| |_|\___\__,_|
- TrackMaze Hacking Group 2013
- $Opciones:
- #1# Cifrar texto sin Clave
- #2# Descifrar texto sin Clave
- #3# Cifrar texto con Clave
- #4# Descifrar texto Con clave
- #5# Salir"""
- while True:
- print "$Entrada: "
- op=input(" #Opcion:")
- if(op==1): #---Cifrar texto sin clave
- mensaje=raw_input(" #Ingrese el mensaje a Cifrar: ")
- columnas=input(" #ingrese la cantidad de columnas: ")
- opcion=raw_input(" #Modo de cifrado, horizontal o vertical: ")
- matriz=Create_matriz(mensaje,columnas,opcion) #Creamos la matriz con la opcion estipulada
- if (opcion=="horizontal"): #segun la opcion, para poder cifrar tenemos que leer la matriz con la opcion contraria (horizontal -> vertical)
- opcion="vertical"
- else:
- opcion="horizontal"
- tex_cifrado=lectura(opcion,matriz)
- print " #Texto Cifrado: ",tex_cifrado
- elif (op==2): #---Descifrar texto sin clave
- mensaje=raw_input(" #Ingrese el mensaje a Descifrar: ")
- columnas=input(" #Ingrese la cantidad de columnas: ")
- opcion=raw_input(" #Modo de Descifrado, horizontal o vertical: ")
- matriz=Create_matriz(mensaje,columnas,opcion)
- if (opcion=="horizontal"):
- opcion="vertical"
- else:
- opcion="horizontal"
- tex_cifrado=lectura(opcion,matriz)
- print " #Texto Descifrado: ",tex_cifrado
- elif (op==3): #---Cifrar texto con clave
- mensaje=raw_input(" #Ingrese el mensaje a Cifrar: ") #ingreso del mensaje
- columnas=input(" #Ingrese la cantidad de columnas: ") #la cantidad de columnas a utilizar
- clave=raw_input(" #Ingrese la clave separada por comas (1,2,..,n): ") #la clave
- matriz=Create_matriz(mensaje,columnas,"horizontal")
- clave=clave.split(",")
- tex_cifrado=cifrado_clave(matriz,clave)
- print " #Texto Cifrado: ",tex_cifrado
- elif (op==4):
- mensaje=raw_input(" #Ingrese el mensaje a Descifrar: ")
- columnas=input(" #Ingrese la cantidad de columnas: ")
- clave=raw_input(" #Ingrese la clave: ")
- matriz=Create_matriz(mensaje,columnas,"vertical")
- clave=clave.split(",")
- tex_descifrado=lectura_clave(matriz,clave)
- print "El texto decifrado es: ",tex_descifrado
- elif (op==5):
- break
- else:
- print " [+] Ingresa una Opcion Valida [+]"
- print "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement