Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import Image
  2.  
  3. import sys
  4.  
  5. import os
  6.  
  7.  
  8.  
  9. r16to0 = range (15,-1,-1)
  10.  
  11. r8to0 = range (7,-1,-1)
  12.  
  13.  
  14.  
  15. def obtbytim(img):
  16.  
  17.  
  18.  
  19.     a1,b1=img.size
  20.  
  21.     imgby=[]
  22.  
  23.     a=0
  24.  
  25.     b=0
  26.  
  27.     while b < b1:
  28.  
  29.         while a < a1:
  30.  
  31.             pix = img.getpixel((a,b))
  32.  
  33.             for color in pix:
  34.  
  35.                 imgby.append(color)
  36.  
  37.             a+=1
  38.  
  39.         a=0
  40.  
  41.         y+=1
  42.  
  43.     return imgby
  44.  
  45.  
  46.  
  47. def enviobyte (byte1, img):
  48.  
  49.    
  50.  
  51.     a1,b1=img.size
  52.  
  53.     a=0
  54.  
  55.     b=0
  56.  
  57.     z=0
  58.  
  59.     size=0
  60.  
  61.     size1=len(byte)
  62.  
  63.     c=[0,0,0]
  64.  
  65.     while b<b1 and size<size1:
  66.  
  67.         while a<a1 and size<size1:
  68.  
  69.             while z<3:
  70.  
  71.                 c[z] = byte1[size]
  72.  
  73.                 z+=1
  74.  
  75.                 size+=1
  76.  
  77.             z=0
  78.  
  79.             img.putpixel( (a,b), (c[0],c[1],c[2]))
  80.  
  81.             a+=1
  82.  
  83.         a=0
  84.  
  85.         b+=1
  86.  
  87.  
  88.  
  89. def esconder(imagen, escon):
  90.  
  91.        
  92.  
  93.     try:
  94.  
  95.         img = Image.open(imagen)
  96.  
  97.         mens = file(escon,'rb')
  98.  
  99.         mensaje = mens.read()
  100.  
  101.         bytetes = obtbytim(img)
  102.  
  103.         escsize = len(mensaje)
  104.  
  105.         byimgsize = len(bytetes)
  106.  
  107.         byte = 0
  108.  
  109.         c = [0,0,0]
  110.  
  111.        
  112.  
  113.         for bit in r16to0:
  114.  
  115.             tmp = (escsize >> bit) & 0x0001
  116.  
  117.             bytetes[ byte ] = 0x0001 | bytetes[byte] if tmp is 1 else 0xfffe & bytetes[byte]
  118.  
  119.             bit-=1
  120.  
  121.             byte+=1
  122.  
  123.        
  124.  
  125.         for c1 in mensaje:
  126.  
  127.             tmp = ord(c1)
  128.  
  129.             for bit in r8to0:
  130.  
  131.                 tmp2 = (tmp >> bit) & 0x01
  132.  
  133.                 bytetes[byte] = 0x01 | bytetes[byte] if tmp2 is 1 else 0xfe & bytetes[byte]
  134.  
  135.                 byte+=1
  136.  
  137.        
  138.  
  139.         enviobyte (bytetes, imgen)
  140.  
  141.  
  142.  
  143.         img.save(imagen+ ".bmp" +img.format, img.format)
  144.  
  145.     except IOError:    
  146.  
  147.         print "no se puede abrir", imagen , "or" , escon
  148.  
  149.     except:
  150.  
  151.         print "error:", sys.exc_info()[0]
  152.  
  153.    
  154.  
  155.     finally:
  156.  
  157.         print "terminado"
  158.  
  159.  
  160.  
  161. if __name__== "__main__":
  162.  
  163.     if len(sys.argv) >2:
  164.         print "entrando imagen" + sys.argv[1]
  165.         print "texto a esconder: " , sys.argv[2]
  166.        
  167.         esconder( sys.argv[1] , sys.argv[2]  )
  168.        
  169.     else:
  170.         print "se perdieron los parametros"