jueves, 1 de noviembre de 2012

Programs to encripting picture

Well, here is the code to encrypt the message:

Code:

import Image #library for use the picture
archivoi = str(raw_input("nombre de la imagen con extencion: ")) ##take a picture
imagen = Image.open(archivoi)
archivom = str(raw_input("nombre del archivo del mensaje maximo 255 caracteres con extencion: ")) ##take a ## file of message
archivo = open(archivom,"r")
archivof = str(raw_input("Nombre final de la imagen extencion png: ")) ##take a final picture name
#nlineas = 0
mensaje = [] ##list for message
#contador = 0
conver = [] ##decimal list of message
cont = 0 ##cont of conver
sizem = 0 ##size for some utility
#pixes = []
ancho, altura = imagen.size ##dimension of picture
#imagen2 = Image.new(imagen.mode, imagen.size)
#f=open("nuevo.bmp","w")
pixels = imagen.load() ##map of the picture
contador = 0 ##cont for some utility
#pixels2 = imagen2.load()
#dis = 0
tam = 0 ##cont for the algorithm
#(r,g,b) = (0,0,0)
#cont = 0 ##cont for the algorithm
rgbb = 0 ##identify for some pixel
identificador = 0 ##value for some caracter for message
## variable's to save pixels for the algorithm
a = 0
b = 0
c = 0
## variable's save pixels for the algorithm
letras = 0
#recx = []
#recy = []
#recl = []
##part to read message
for i in archivo.xreadlines():
dato = i
mensaje.append(dato)
cont = cont + len(dato)
letras = letras + len(dato)
sizem = len(mensaje) ##save the size of message
##part to transform to messege at decimal format
for i in range(sizem):
size = len(mensaje[i])
for j in range(size):
conver.append(ord(mensaje[i][j]))
#for x in range(ancho):
# for y in range(altura):
# pix = pixels[x,y]
# pixes.append(pix)
# contador = contador + 1
#b = b + 1
#a = a + 1
####parameters for algoritm
multi = ancho * altura ##calculate the area of picture in pixels
##separar = multi/4 ##
size = int(len(conver))##size of messege in decimal
separacion = multi/size ##separation of the pixels
#print "separacion 1",separacion,"multiplicacion :",multi,""
indicador = 0 ##for some condicion
alfa = 0 #for some condition
constante = separacion/4 ##for the algorithm
control = 0 ##for the algorithm
#rlist = []
#pas = 0
#print "valor de separar:",separar
cantidades = 0
#print "altura:",altura,"ancho",ancho,""
#print "separacion",separacion
#print "constante: ",constante
##algoritm
##read all the map pixels
for i in range(ancho):
for j in range(altura):
(a,b,c) = pixels[i,j] ##save the pixels in three variable
if cantidades == 0: ## part to save to size of the message
mod = c % 7 ## and used to the desencripted
if mod == 1:
r = size
pixels[i,j] = (r,b,c) ##r hidden to size in this pixel
cantidades = cantidades + 1 ##this condicion only one pass time
#print "pase una sola vez: ",r
#print "kugari: ",i,"lugar j",j,""
#print "sixe: ",r
else:
if alfa < separacion:
if cont > 0: ##if the messege have one more caracter
identificador = conver[tam] ##save the caracter
##what pixel we used if r or g or b
if rgbb == 0:
r = conver[tam] #save the caracter
pixels[i,j] = (r,b,c) #hidden in the pixel
tam = tam + 1 #plus for posterior comparation
cont = cont - 1 ##reset the size of messege
alfa = separacion
#recx.append(i)
#recy.append(j)
#recl.append(rgbb)
#print "i: ",i,"j",j,""
if rgbb == 1: ##its the same the other only change the pixel
g = conver[tam] ##now is b
pixels[i,j] = (a,g,c)
tam = tam + 1
cont = cont - 1
alfa = separacion
#recx.append(i)
#recy.append(j)
#recl.append(rgbb)
if rgbb == 2: ##its the same that others
B = conver[tam]
pixels[i,j] = (a,b,B)
tam = tam + 1
cont = cont - 1
alfa = separacion
#recx.append(i)
#recy.append(j)
#recl.append(rgbb)
if control >= separacion: #used this for jumping pixels
separacion = separacion + constante/2
alfa = 0
control = control + 1 ##for cont message caracter's
##change the pixle r or g or c
if rgbb == 0:
rgbb = 1
else:
if rgbb == 1:
rgbb = 2
else:
if rgbb ==2:
rgbb = 0
print "contrl",letras
print "si se puso todos ?:",tam
print ""
#contador = 0
imagen.save(archivof) ##save the new picture
#print contador
#print pixels[0,0]
#print letras
#print conver
view raw encript.py hosted with ❤ by GitHub
Code:


and this is the code to desencript message:
##its de same algoritm the only diference its the start, the algoritm read the size
##of messge of the picture and use the same algoritm to desencript
import Image
archivoi = str(raw_input("Nombre de la imagen a desifrar: "))
imagen = Image.open(archivoi)
pixel = imagen.load()
ancho, altura = imagen.size
mensaje = []
contador = 0
letra = 0
a = 0
b = 0
c = 0
size = 0
multi = ancho * altura
separacion = 0
alfa = 0
rgbb = 0
tam = 0
cont = 0
control = 0
constante = 0
rgbb = 0
i = 0
j = 0
r = 0
g = 0
b = 0
for i in range(ancho):
for j in range (altura):
(a,b,c) = pixel[i,j]
if contador == 0:
mod = c % 7
if mod == 1:
size = a
cont = int(size)
multi = ancho * altura
separacion = multi/cont
constante = separacion/4
print "pase una sola vez"
print "size = ",cont
#print "altura : ",altura,"ancho: ",ancho,"total: ",multi,""
#print "separacio: ",separacion
#print "constante :",constante
contador = 2;
else:
if alfa < separacion:
if cont > 0:
if rgbb == 0:
#(a,b,c) = pixel[i,j]
mensaje.append(chr(a))
tam = tam + 1
cont = cont - 1
alfa = separacion
if rgbb == 1:
#(a,b,c) = pixel[i,j]
mensaje.append(chr(b))
tam = tam + 1
cont = cont - 1
alfa = separacion
if rgbb == 2:
#(a,b,c) = pixel[i,j]
mensaje.append(chr(c))
tam = tam + 1
cont = cont - 1
alfa = separacion
if control >= separacion:
separacion = separacion + constante/2
alfa = 0
control = control + 1
if rgbb == 0:
rgbb = 1
else:
if rgbb == 1:
rgbb = 2
else:
if rgbb == 2:
rgbb = 0
print "mi mensaje:",mensaje
print "size del mensaje:",len(mensaje)
view raw desencrip.py hosted with ❤ by GitHub
Code:

The pictures to have a message is 2,5,6 of the before post


if we use the python program, this genereted the follow messege:

picture 5:


and the messege:


picture 6:

and the messege


thats all my folks

the images were uploaded to mediafire for blogger issues that can change the images
In the before post