Skip to main content

Snyk Fetch the Flag CTF 2023 writeup: Honey Baked Messages

Written by:
snyk-ctf-2023-honey-baked-messages

November 30, 2023

0 mins read

Thanks for playing Fetch with us! Congrats to the thousands of players who joined us for Fetch the Flag CTF. If you were at Snyk’s 2023 Fetch the Flag and are looking for the answer to the Honey Baked Messages challenge, you’ve come to the right place. Let’s walk through the solution together!

This challenge focuses on the idea of Hamming codes. Hamming codes are a type of error-correcting codes. This challenge uses the (7, 4) version of Hamming codes.

The challenge consists of these parts:

  1. Understand that this is Hamming coding.

  2. Read in each line of the file. 

  3. Determine the needed H matrix for the problem.

  4. Error correct the entire file and get the flag.

Here is the solve.py solution script:

import numpy as np

H = np.array(
        [
            [1, 1, 1, 0, 1, 0, 0],
            [0, 1, 1, 1, 0, 1, 0],
            [1, 1, 0, 1, 0, 0, 1]
        ]
    )
errors = {
    "000":None,
    "001": 6,
    "010": 5,
    "011": 3,
    "100": 4,
    "101": 0,
    "110": 2,
    "111": 1
}

def np2usable(nparr):
    return np.array2string(nparr).replace(" ", "" ).replace("[", "").replace(']', "")

def fixErrs(hamming):
    error = (np.matmul(H, hamming)%2)
    err_idx = errors[np2usable(error)]
    if err_idx != None:
        # print(err_idx)
        hamming[err_idx] +=1
        hamming[err_idx] %= 2

    return hamming[:4]

data = []
with open("message_2.txt", "r") as reader:
    for line in reader:
        code = np.fromstring(" ".join(line.strip("\n")), dtype = int, sep=" ")
        data.append(np2usable(fixErrs(code)))
split_chars = (list(zip(*(iter(data),) * 2)))

[print(chr(int(j+k, 2)), end="") for j,k in split_chars ]

Thanks for making Fetch happen!

A huge thank you to all the teams in Fetch the Flag 2023! It was great seeing all of you there and you can always find me on YouTube.

Here are the writeups for the other 2023 challenges. Dig in!

Posted in:
snyk-ctf-2023-honey-baked-messages

Capture the Flag 101 Workshop

Check out this hands-on, virtual workshop to learn how to Capture the Flag (CTF) challenges, including pwn and web. After the workshop, you'll have the security skills and experience to compete in CTFs.