Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created May 6, 2016 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgrahamc/e06647f41ed6d7c726fee8d1d428337f to your computer and use it in GitHub Desktop.
Save jgrahamc/e06647f41ed6d7c726fee8d1d428337f to your computer and use it in GitHub Desktop.
Small perl program to read the SETI Decrypting Challenge binary data and output PNG files
# http://phl.upr.edu/library/notes/SETIChallenge
use strict;
use warnings;
use GD;
my @seti;
my $in = 'SETI_message.txt';
open S, "<$in" or die "Failed to open $in";
while (<S>) {
push @seti, split(//, $_);
}
close S;
my $cols = 359;
my $rows = 757;
my $images = 7;
for my $i (0..$images-1) {
my $img = new GD::Image($cols, $rows);
my $wh = $img->colorAllocate(255, 255, 255);
my $bl = $img->colorAllocate(0, 0, 0);
for my $r (0..$rows-1) {
for my $c (0..$cols-1) {
my $p = ($seti[$i*$cols*$rows+$c+$r*$cols] eq '0')?$bl:$wh;
$img->setPixel($c, $r, $p);
}
}
my $out = "seti-part-$i.png";
open P, ">$out" or die "Failed to create $out";
print P $img->png;
close P;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment