Cracking Simple Image Codes Using Python

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Cracking Simple Image Codes Using Python

Post by Th3_M4d_H4tt3r on Thu Jun 20, 2013 3:11 am
([msg=76182]see Cracking Simple Image Codes Using Python[/msg])

here is the code,

Code: Select all
from PIL import Image
import sys
import time

img = Image.open(sys.argv[1])
img = img.convert("RGB")

pixdata = img.load()

a = 0.2 * 255

for y in xrange(img.size[1]):
   for x in xrange(img.size[0]):
      print "Bruteforcing pixel "+str(x)+", "+str(y)+"   "
      print "\033[2A"

      pixel = pixdata[x, y]
      lumin = pixel[0] * 0.299 + pixel[1] * 0.587 + pixel[2] * 0.114

      if lumin < a:
         pixdata[x, y] = (0, 0, 0)
      else:
              pixdata[x, y] = (255, 255, 255)

print "Done bruteforce, opening image..."
print "Finished in "+str(time.clock())

img.show()


the image I cracked with this is:
Image
Last edited by Th3_M4d_H4tt3r on Thu Jun 20, 2013 6:18 am, edited 1 time in total.
Tip me if I helped you!
BTC Address: 15wu8gxFAemZH3jC4km3Z8gMYtKHLxpnEv
User avatar
Th3_M4d_H4tt3r
Experienced User
Experienced User
 
Posts: 54
Joined: Tue Jun 18, 2013 8:25 am
Blog: View Blog (0)


Re: Cracking Simple Image Codes Using Python

Post by pretentious on Thu Jun 20, 2013 5:44 am
([msg=76184]see Re: Cracking Simple Image Codes Using Python[/msg])

Nice. It's been a while since i've looked into this stuff. Is the next step to seperate each indervidual character?
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
pretentious wrote:Welcome to bat country
User avatar
pretentious
Contributor
Contributor
 
Posts: 607
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: Cracking Simple Image Codes Using Python

Post by Th3_M4d_H4tt3r on Thu Jun 20, 2013 6:17 am
([msg=76185]see Re: Cracking Simple Image Codes Using Python[/msg])

yes, I am working on that now :) i also updated the code; over 20x faster.
Tip me if I helped you!
BTC Address: 15wu8gxFAemZH3jC4km3Z8gMYtKHLxpnEv
User avatar
Th3_M4d_H4tt3r
Experienced User
Experienced User
 
Posts: 54
Joined: Tue Jun 18, 2013 8:25 am
Blog: View Blog (0)


Re: Cracking Simple Image Codes Using Python

Post by pretentious on Tue Oct 01, 2013 6:05 am
([msg=77536]see Re: Cracking Simple Image Codes Using Python[/msg])

I've had your code on my HDD just waiting to be played with. Here's something completely different i put together
Code: Select all
from PIL import Image
import sys
import time

img = Image.open(sys.argv[1])
tiles = int(sys.argv[2])
img = img.convert("RGB")

pixdata = img.load()

for y in range(0, img.size[1], (img.size[1]/tiles)):
   for x in range(0, img.size[0], (img.size[0]/tiles)):
      #print x, y
      red = 0
      green = 0
      blue = 0
      cells = 0
      for yi in range(y, (y+(img.size[1]/tiles)),1):
         for xi in range(x, (x+(img.size[0]/tiles)),1):
            cells = cells + 1
            pixel = pixdata[xi, yi]
            red = red + pixel[0]
            green = green + pixel[1]
            blue = blue + pixel[2]
      for yi in range(y, (y+(img.size[1]/tiles))):
         for xi in range(x, (x+(img.size[0]/tiles))):
                  pixdata[xi, yi] = (red/cells,green/cells,blue/cells)
img.show()

I'm in love with pythons simple API's. This takes an image and effectively pixelates it. I wanted to achive a proper bluring effect by making the squares bleed into each other but had other stuff to do. Anyone want to pick up where i left off?
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
pretentious wrote:Welcome to bat country
User avatar
pretentious
Contributor
Contributor
 
Posts: 607
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests