HACKvent 2020 - Day 4

01-01-2021 - 1 minute, 25 seconds - CTF

Challenge - HV20.04 Br❤️celet

Santa was given a nice bracelet by one of his elves. Little does he know that the secret admirer has hidden a message in the pattern of the bracelet…

Image of a bracelet with pearls of different color

Over the day, two sets of hints were given:

  1. No internet is required - only the bracelet (#1)
  2. The message is encoded in binary (#1)
  3. Violet color is the delimiter (#2)
  4. Colors have a fixed order (#2)
  5. Missing colors matter(#2)

Solution

We started the challenge in the afternoon, when all hint were already given. It was thus relatively straight forward. Counting the beads and bringing it to paper (text document) was tedious however 😉 The thought process was something like this:

If V is the delimiter, we have 26 elements. With binary encoding (hint 1), and just 4 remaining colors thats just 4 bit. I can’t make a printable character with 4 bits. Lets treat them as high&low nibble pairs then.

And indeed, that was the solution. The following code returned the flag:

static void SolveDay4()
{
    string beadColors = "GVPYVGBVPGVGBVPGBYVGBYVGBVBYVBYVGBYV"
                      + "PYVBYVVGBYVGYVGYVBYVBYVGVGBVPGBVBYVGBYVBYVGV";
    // V(iolet) is the delimiter
    string[] elements = beadColors.Split(new char[]{'V'});

    for(int i = 0; i < elements.Length-1; i+=2)
    {
        byte value = 0;
        var highNibble = elements[i];
        var lowNibble = elements[i+1];

        // PGBY represents 0b1111
        // If a color is missing, the bit is 0
        if (highNibble.Contains("P"))
            value |= (1 << 7);
        if (highNibble.Contains("G"))
            value |= (1 << 6);
        if (highNibble.Contains("B"))
            value |= (1 << 5);
        if (highNibble.Contains("Y"))
            value |= (1 << 4);

        if (lowNibble.Contains("P"))
            value |= (1 << 3);
        if (lowNibble.Contains("G"))
            value |= (1 << 2);
        if (lowNibble.Contains("B"))
            value |= (1 << 1);
        if (lowNibble.Contains("Y"))
            value |= (1 << 0);

        Console.Write((char)value);
    }
}

The resulting flag was HV20{Ilov3y0uS4n74}.

Next Post Previous Post