Skip to content

Instantly share code, notes, and snippets.

@leonjza
Last active July 10, 2023 15:05
Show Gist options
  • Save leonjza/cb9034e7b4ca81d064621dcc54705cf1 to your computer and use it in GitHub Desktop.
Save leonjza/cb9034e7b4ca81d064621dcc54705cf1 to your computer and use it in GitHub Desktop.
SenseCon '23 Announcement Challenge
<?
class Message {
private $message = "This was the announcement challenge for SenseCon '23, our annual internal @sensepost hackathon. Have fun solving it!";
function echo_it() {
echo $this->message . PHP_EOL;
}
function write($message, $source, $target) {
$binary = '';
for ($i = 0; $i < mb_strlen($message); ++$i) {
$character = ord($message[$i]);
$binary .= str_pad(decbin($character), 8, '0', STR_PAD_LEFT);
}
$binary .= '00000011';
$img = imagecreatefrompng($source);
$pos = 0;
for ($y = 0; $y < imagesy($img); $y++) {
for ($x = 0; $x < imagesx($img); $x++) {
if (!isset($binary[$pos])) break 2;
$colors = imagecolorsforindex($img, imagecolorat($img, $x, $y));
$blue = str_pad(decbin($colors['blue']), 8, '0', STR_PAD_LEFT);
$blue[strlen($blue) - 1] = $binary[$pos] == '1' ? '0' : '1';
$newBlue = bindec($blue);
$newColor = imagecolorallocatealpha(
$img, $colors['red'], $colors['green'], $newBlue, $colors['alpha']);
imagesetpixel($img, $x, $y, $newColor);
$pos++;
}
}
imagepng($img, $target, 9);
imagedestroy($img);
}
}
$t = new Message;
$t->echo_it();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment