FV25.22 - The crib in the genome

Difficulty
easy

Categories
crypto

Description
When the aliens left the earth a long time ago, they left us a message in the genome. Our high-tech instruments have extracted the encoded message from the genome of an average human. Interestingly, they used a kind of 8-bit ASCII encoding, but since the Rendlesham Forest incident, this should not come as a huge surprise. It also seems that they used the expression "DNA encoding" in the message.

Author
brp64
Flagvent 2025 - Day 22 - the-crib-in-the-genome.tar.gz

Solution

A strange looking enc.text file is provided to us:

GCCTGGATAGATGTATACGTTCATCTGTTTGTCGATTCATCTGTTAATGGATAGATGCGTCGACCCACGTATGGATGGATCTATCCACTTGTGCGTTTATCCACGGATATATCCACCTGTCAATTTATCCACGCATACGTTAATACATCCACCTCTAGCTTCCTCCACTTATAGATGCATGGATCTATTAATAGATGTATAGACCCACCCACCACTTTATACGTTTATCCACTAATGCGTCCACTAGTGGATTTGTACGTCCACATATCGATTCATGTATCCACATCTATTTACGCTTGCGAGTCTCTAGCTTCCTGGTTGCGCAGATGCATCCGCCTATGCGCCTATGGTTATATTCGCCTGCATGCTGGT

Based on the challenge title, we realise this is genetic code. The challenge description also hints that the code is being used as an 8-bit ASCII encoding. Therefore, every 4-byte chunk in the encoded text (for example, CCTG) becomes 1 byte in the decoded ASCII.

We need a 2-bit binary mapping for each of the four DNA bases: cytosine (C), guanine (G), thymine (T), and adenine (A). This lets us build an 8-bit value, which we can then map to a single ASCII character. We also need to consider whether the bits are interpreted using little-endian or big-endian ordering..

Since the challenge description mentions that "DNA encoding" will appear in the plaintext, we can write a script to brute-force all possible mappings and identify the correct decoding:

import itertools

with open("enc.text", "r") as f:
    data = f.read().strip().replace("\n", "")

for p in itertools.permutations(["00", "01", "10", "11"]):
    mapping = dict(zip("ACGT", p))
    bits = "".join([mapping.get(c, "") for c in data])
    
    for lsb in [False, True]:
        decoded = ""
        for i in range(0, len(bits), 8):
            chunk = bits[i:i+8]
            
            if lsb:
                chunk = chunk[::-1]

            val = int(chunk, 2)
            decoded += chr(val)

        if "DNA encoding" in decoded:
            mode = "LSB" if lsb else "MSB"
            print(f"FOUND! Mapping: {p}, Mode: {mode}")
            print(decoded)
            break

Running this script produces a message containing our daily flag!

FOUND! Mapping: ('01', '00', '11', '10'), Mode: LSB
Congratulations, good use of the crib DNA encoding.  Here is your flag FV25{DNA_3nc0d3d_f146}

Flag:

FV25{DNA_3nc0d3d_f146}

External discussions


Leave a comment

(required)(will not be published)(required)

Comments

There are no comments yet. Be the first to add one!