Skip to content

Instantly share code, notes, and snippets.

@leonjza
Last active July 10, 2023 15:05
Show Gist options
  • Select an option

  • Save leonjza/cb9034e7b4ca81d064621dcc54705cf1 to your computer and use it in GitHub Desktop.

Select an option

Save leonjza/cb9034e7b4ca81d064621dcc54705cf1 to your computer and use it in GitHub Desktop.

Revisions

  1. leonjza revised this gist Jul 10, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # SenseCon '23 Announcement Challenge

    The image in this tweet is needed to solve this challenge: https://twitter.com/leonjza/status/1678419863436443648
  2. leonjza created this gist Jul 10, 2023.
    47 changes: 47 additions & 0 deletions message.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?

    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();