Binary Codes & Puzzles

How to Decode a Binary Cipher Puzzle Using ASCII

Decode a binary cipher puzzle with an ASCII example, preserve spaces and punctuation, and learn why binary encoding alone is not encryption.

Binary Translator
  • ASCII
  • Binary Puzzles
  • Text Encoding
On this page

The puzzle at hand is the decoding of an unknown cipher that involves binary, or base-2, encoding. In this case, you can use the fact that it's not encryption defined through a cryptographic algorithm and key — it’s instead a form of what we might term “reversible character encoding.” That means that there exists a public table lookup that defines how characters are encoded as bits (binary digits), allowing us to recover them.

What defines a cipher in the world of cryptography?

In the world of cryptography, a cipher can be defined either through a cryptographic algorithm and associated secret key or without one, depending on its intended use. Encryption algorithms usually rely upon the concept of keys; without them, the ciphertext would have no meaning. There are other cases where you can encode text without a secret key, however. These ciphers may rely upon some shared knowledge between participants rather than requiring each person to know the secret.

This distinction is important because it tells you whether you can expect a secret key or some other kind of mapping to decode the data. This is where ASCII comes in handy: It’s a public number-to-character mapping. The ASCII standard is available for anyone who wants it, but the problem is that the number doesn’t always directly map to the intended character.

Binary text puzzle diagram showing an ASCII lookup route and an alternative puzzle-rule route with a conditional key.

For example, suppose someone wanted to encode the letter H as 1001000, and the letter I as 1001001. Each of these groups is seven bits long, and their numeric values are both 72 and 73, respectively. So if you were told that you needed to look up numbers from 0 through 127 to get your letters, the answer would appear straightforward. But there are more possibilities.

You can see the issue: If you simply take the bit representation alone, then there’s no added secret key. Therefore, this isn’t an instance of encryption defined through a cryptographic algorithm and key. The problem here is that there could be other mappings: One such example is the alphabet variant known as Bacon’s cipher, which maps characters to sequences of A and B. In addition, you need to account for any symbol conventions being used.

Decoding a short message

Let’s assume that the groupings shown below were provided to us:

01001000 01001001

01001000

01001001

We’ll decode the first two groups, which represent the bytes 0x48 and 0x49, which are “H” and “I” in ASCII.

Each group is treated as a separate byte, and we’ll perform successive lookups for each byte by translating it into decimal notation and then using that to find the corresponding character in the ASCII table.

So:

01001000 → decimal 72 → H

01001001 → decimal 73 → I

That gives us the decoded output as HI.

If you have more groups to decode, you’d continue this process until all of the groups are decoded. As before, we’ll convert each group to its decimal equivalent, then use the ASCII table to translate it into the correct letter.

Retaining message spaces and punctuation

In some cases, you may also be required to retain the message’s original spaces and punctuation. For example, the following message uses a series of groups that are separated by spaces:

01001000 01001001 00100000 01001000 01001001 00100001

In this case, you must distinguish between the separators used to display the bit groups and those that represent actual characters within the recovered message. To do so, you must recognize that certain groupings represent specific characters, like the space, as shown below.

00100000 → space

00100001 → !

Putting it all together, the message becomes:

HI HI!

In this scenario, the displayed intergroup spaces represent separation of bit groups, and the encoded space represents a character within the recovered message.

Group lengths and possible mappings

Another clue to help determine what the underlying cipher might be lies in the length of the groupings themselves. Some ciphers involve grouping bits based on a fixed size, often 5 bits for the Bacon cipher. You should check the group lengths for possible clues about the cipher used. However, you should remember that ASCII itself presents a slightly different view, as ASCII typically uses 8-bit representations for characters.

ASCII presents an interesting challenge in this regard, especially when considering how it differs from the alphabet variant known as Bacon’s cipher. The most basic form of Bacon’s cipher maps each plaintext letter into a pattern of five A/B symbols, as shown below.

Bacon’s cipher: Five A/B symbols per plaintext letter

A → AAAAA

B → AAAAB

C → AAABA

D → AAABB

E → AABAA

F → AABAB

G → AABBA

H → AABBB

I → ABAAA

J → ABAAB

K → ABABA

L → ABABB

M → ABBAA

N → ABBAB

O → ABBBA

P → ABBBB

Q → BAAAA

R → BAAAB

S → BAABA

T → BAABB

U → BABAA

V → BABAB

W → BABBA

X → BABBB

Y → BBAAA

Z → BBAAB

As shown, there are only two unique symbols used: A and B. Because of this, the simple visible version of Bacon’s cipher has a shared alphabet and requires no secret key to decode. Another alphabet variant merges the I/J and U/V pairs, while another alternative separates patterns for I, J, U, and V.

Five-bit grouping alone isn’t enough to identify Bacon’s cipher.

However, just having the groups with five bits doesn’t necessarily mean that they represent Bacon’s cipher. We’re looking for five-bit groupings in the data. However, in this example, each group is composed of 8 bits. The difference is the way they are presented. In this case, the ASCII presentation is a sequence of eight bits, while the Bacon cipher presents sequences of five bits.

It’s also possible that you can’t identify the correct cipher by checking the groupings alone, and you must instead consider any specified alphabet or additional cipher rules.

Tracing unreadable output

If the output appears unreadable, then you must consider three things: Did you copy and group the data correctly? Was the stated encoding correct? And did you follow any specified rules for the given cipher, such as a particular alphabet or other rule? In the first place, you want to make sure that the groups that you copied matched the puzzle’s stated grouping. Second, verify that you checked the intended encoding before interpreting the output. Finally, ensure that you applied any additional rules that might’ve been specified, like using a particular alphabet.

If the output still seems unreadable, you can attempt to compare your results with the expected results. For example, perhaps the puzzle was designed using a specific cipher like Bacon’s. However, the problem is that there are many variations of the Bacon cipher, and without knowing the exact one being used, it will be impossible to interpret the data. You must also consider any alternative alphabets or other transformations that may apply. While you can attempt to decode the data using different cipher techniques, you won’t know for sure unless you know exactly which transformation was applied.

Sources