a weblog about programming, hacking, linux, and other randomness

My Photo
I'm a Programmer, Hobby Hacker, and Linux Freak.

Wednesday, January 7, 2009

Visual Code Representation Using PHP

I sometimes get the feeling I should have been a graphics programmer rather than a web programmer. I always seem to get some sort of satisfaction from communicating data visually. Aside from the quickly outdated GoogleGraph class I wrote to wrap the Google Chart API, nothing I've created in this field have rendered useful. But this doesn't stop me from dreaming up new ways of using the GD libraries.

SteganoCrypt:

My first adventure with GD was steganography. I wanted to create a way of hiding data within the color values of randomly generated pixels. I became completely consumed. Over the span of a week I had added more and more methods of encoding until...my brain exploded. SteganoCrypt (I'm a pro at choosing cheesy camel-cased project names) had it all: multiple substitution ciphers, integrity check bits, password protection. All self contained within the colored pixels of an otherwise scrambled image. Maybe one day I will dig the source out of my CVS attic and post it here. Until then, have a crack at an encrypted message. If you can manage to decipher it, you'll win a cookie.

Character Representation:

Today I wanted to see what a website would look like after multiple character occurrences are organized and color coded. Each span of color represents the amount of similar characters used throughout the code, placed in order by first occurrence. The more 'A's there are, the longer a span of color. As you can see the spans become shorter as the code progresses because less frequently used characters are picked up later in the process. Image width is determined by the amount of total characters in the code. Here is this actual post after processing. I don't know what character #2F1400 represents, but apparently I use it a lot.

Google vs. Yahoo vs. MSN Comparison:



While completely useless, this does give an interesting perspective of bloat. It can essentially be duplicated with:
echo strlen(file_get_contents('http://website'));
The three white pixels at the end of each span were added last second to help differentiate colors. Rather than an attached file, I present to you the thrown together code.
$file = file_get_contents('http://ryonsherman.blogspot.com');

$width = strlen($file) / 100;
$height = strlen($file) / $width;

$seed = ord($file[strlen($file)/2]);

$img = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($img, 255, 255, 255);

$chars = array();
for($i = 0; $i < x =" -1;" y =" 0;" index =""> $count) {
$r = $g = $b = $index;
$g *= $seed * 1.5;
$b *= $seed * 2;
$color = imagecolorallocate($img, $r, $g, $b);

for($i = 0; $i < $count; $i++) { ($x > $width) ? eval('$x = 0; $y++;') : $x++;
imagesetpixel($img, $x, $y, (in_array($i, array($count-1, $count-2, $count-3))) ? $white : $color);
}
}

header('Content-type: image/png');
imagepng($img);
imagedestroy($img);

0 comments:

Post a Comment