News for hackers. Stuff that matters.
Re:Coding Challenge for MI5 by guessmyname on Sunday September 11, 2016 @12:13PM (#12474045)
1. Open PNG in text editor, see comment:

    As I read, numbers I see. 'Twould be a shame not to
    count this art among the great texts of our time
2. Threshold so some of the pixels are black and others are white. Save as ASCII PBM.

3. Strip the PBM header lines and remove newlines so that it's just 0's and 1's.

4. Now feed it through this program:

    #include <stdio.h>
    main() {
      int c, l=0, n=1;
      while(EOF != (c=getchar())) {
        if(c == l) n++;
        else {
          putchar(n);
          n=1;
        }
        l = c;
      }
      putchar('\n');
      return 0;
    }
Output is the following:

    43-6F-6E-67-72-61-74-75-6C-61-74-69-6F-6E-73-2C-20-79-6F-75-20-73-6F-
    6C-76-65-64-20-74-68-65-20-70-75-7A-7A-6C-65-21-20-57-68-79-20-64-6F-
    6E-92-74-20-79-6F-75-20-61-70-70-6C-79-20-74-6F-20-6A-6F-69-6E-20-6F-
    75-72-20-74-65-61-6D-3F-20-6D-69-35-2E-67-6F-76-2E-75-6B-2F-63-61-72-
    65-65-72-73-20
5. This smells like ASCII, let's decode it with tr -d - | xxd -p -r

> Congratulations, you solved the puzzle! Why dont you apply to join our team? mi5.gov.uk/careers

From: https://archive.rebeccablacktech.com/g/thread/52888920#p5289...

Re:Coding Challenge for MI5 by basemntunivrse on Sunday September 11, 2016 @12:45PM (#12474202)
I'm a little disappointed that I was able to solve it so quickly, I thought it was going to be a big multi-stage puzzle where the color values and image dimensions/row boundaries would all be important factors...

Still, my solution (in JS) was a little more verbose than yours...

  <img src="puzzle2.png" id="puzzle-image">
  <script>

  /*
  Pink (white) 232,3,138
  Blue (black) 58,185,229
  */

  window.addEventListener("load", function() {
    var image = document.getElementById("puzzle-image"),
      canvas = document.createElement("canvas"),
      context = canvas.getContext("2d");
    canvas.width = image.width;
    canvas.height = image.height;
    context.drawImage(image, 0, 0, image.width, image.height);
    
    // Test 1  - rle
    (function() {
      var rle = [], prev = null, count = 0;
      for (let y = 0; y < image.height; y++) {
        for (let x = 0; x < image.width; x++) {
          let pd = context.getImageData(x, y, 1, 1).data;
            if (prev === null) {
              prev = pd[0];
            }
            if (pd[0] == prev) {
              count++;
            } else {
            rle.push(count);
            count = 1;
            prev = pd[0];
          }
        }
      }
      var r1 = "";
      for (let i = 0; i < rle.length; i++) {
        r1 += String.fromCharCode(rle[i]);
      }
      console.log(r1);
      var r2 = "";
      for (let i = 0; i < r1.length; i += 3) {
        r2 += String.fromCharCode(parseInt(r1[i] + r1[i + 1], 16));
      }
      console.log(r2);
    }());
  }, false);

  </script>
(Where puzzle2.png is the image in black & white)

(Edited to fix indentation...)

Re:Coding Challenge for MI5 by teh_klev on Sunday September 11, 2016 @01:16PM (#12474390)
You could have written this up in a Gist or PasteBin, provided a link and a spoiler message.
Re:Coding Challenge for MI5 by networked on Sunday September 11, 2016 @02:54PM (#12474974)
My solution:

  #!/bin/sh
  wget https://www.mi5.gov.uk/sites/default/files/u2/puzzle.png
  convert puzzle.png puzzle.xpm # Convert the image to XPM with ImageMagick.
  # Here is what the contents of puzzle.xpm looks like:
  # http://pastebin.com/0PySSAXx. The spaces represent one color and the dots
  # the other. We'll replace the spaces with underscores for readability.
  <puzzle.xpm tr ' ' _ \
  | tr -d "\n" \
  | sed -e 's|","||g;   s|^.*\*/"||;   s|".*$||   # Remove metadata, C framing.' \
  | sed -e 's|_\.|_\n.|g;   s|\._|.\n_|g   # New line on color change. ' \
  | awk '{printf "%c", length($0)}' \
  | xxd -r -p
The XPM image file format (https://en.wikipedia.org/wiki/X_PixMap) is great for doing things like this. I find it easier to read and to edit by hand than the Netpbm format family. It seems ImageMagick can't write XPM2, though, which makes extra preprocessing necessary.
Re:Coding Challenge for MI5 by f_allwein on Sunday September 11, 2016 @12:39PM (#12474173)
Huh. So who benefits from you posting the solution here?
Re:Coding Challenge for MI5 by Retr0spectrum on Sunday September 11, 2016 @01:27PM (#12474443)
It's not like its a particularly complex puzzle. If you don't want spoilers, don't read it.
Re:Coding Challenge for MI5 by estefan on Sunday September 11, 2016 @05:44PM (#12475896)
Can you spoil the latest Bourne film for me as well please?
Re:Coding Challenge for MI5 by cureyourhead on Sunday September 11, 2016 @12:22PM (#12474080)
Well done!