Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image
- import sys
- import os
- r16to0 = range (15,-1,-1)
- r8to0 = range (7,-1,-1)
- def obtbytim(img):
- a1,b1=img.size
- imgby=[]
- a=0
- b=0
- while b < b1:
- while a < a1:
- pix = img.getpixel((a,b))
- for color in pix:
- imgby.append(color)
- a+=1
- a=0
- y+=1
- return imgby
- def enviobyte (byte1, img):
- a1,b1=img.size
- a=0
- b=0
- z=0
- size=0
- size1=len(byte)
- c=[0,0,0]
- while b<b1 and size<size1:
- while a<a1 and size<size1:
- while z<3:
- c[z] = byte1[size]
- z+=1
- size+=1
- z=0
- img.putpixel( (a,b), (c[0],c[1],c[2]))
- a+=1
- a=0
- b+=1
- def esconder(imagen, escon):
- try:
- img = Image.open(imagen)
- mens = file(escon,'rb')
- mensaje = mens.read()
- bytetes = obtbytim(img)
- escsize = len(mensaje)
- byimgsize = len(bytetes)
- byte = 0
- c = [0,0,0]
- for bit in r16to0:
- tmp = (escsize >> bit) & 0x0001
- bytetes[ byte ] = 0x0001 | bytetes[byte] if tmp is 1 else 0xfffe & bytetes[byte]
- bit-=1
- byte+=1
- for c1 in mensaje:
- tmp = ord(c1)
- for bit in r8to0:
- tmp2 = (tmp >> bit) & 0x01
- bytetes[byte] = 0x01 | bytetes[byte] if tmp2 is 1 else 0xfe & bytetes[byte]
- byte+=1
- enviobyte (bytetes, imgen)
- img.save(imagen+ ".bmp" +img.format, img.format)
- except IOError:
- print "no se puede abrir", imagen , "or" , escon
- except:
- print "error:", sys.exc_info()[0]
- finally:
- print "terminado"
- if __name__== "__main__":
- if len(sys.argv) >2:
- print "entrando imagen" + sys.argv[1]
- print "texto a esconder: " , sys.argv[2]
- esconder( sys.argv[1] , sys.argv[2] )
- else:
- print "se perdieron los parametros"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement