Persian Türkçe English

Binary Code Decoding Challenge

Challenge Objective

In this challenge, you need to decode a binary string (consisting of 0s and 1s) into its original text. To do this, you must convert the binary codes to their corresponding characters or words based on the provided table.

Key Points:

  • Prefix-free encoding: No code is a prefix of another code, which allows unambiguous decoding.
  • Shorter codes for frequent letters: Common English letters like E, T, A, O, I, N have shorter binary codes.
101010 111 001 010 111 000 111...

Encoding Table

The table below shows each English alphabet letter with its unique binary code:

Letter Binary Code Letter Binary Code Letter Binary Code
A 1101 J 010000 S 01101
B 10110 K 10001 T 0101
C 0001 L 0111 U 10111
D 0110 M 11000 V 000001
E 111 N 1001 W 10101
F 00101 O 0011 X 001001
G 01001 P 11101 Y 0100001
H 00001 Q 11001 Z 11100
I 1010 R 10000 SPACE 00000

Decode Binary Sequence

The program below helps you decode binary sequences based on the encoding table above:

Decoded Result:

Result will appear here...

Binary code examples

Below are two examples of binary code that you can copy and paste into the decryption section:

First example:

            10101 111 0111 0001 0011 11000 111 0101 0011 0101 00001 111 0001 
            0011 11000 11101 111 0101 1010 0101 1010 0011 1001 0011 1001 111 
            1010 0110 111 1101 0011 1001 111 1010 0110 111 1101 0011 1001 
            10101 0011 10000 0111 0110 0101 10111 10000 10001 111 0100001
                    

Second example:

            10101 111 0111 0001 0011 11000 111 00000 0101 0011 00000 0101 00001 111 00000 0001 
            0011 11000 11101 111 0101 1010 0101 1010 0011 1001 00000 0011 1001 111 00000 
            1010 0110 111 1101 00000 0011 1001 111 00000 
            10101 0011 10000 0111 0110 00000 0101 10111 10000 10001 111 0100001
                    

About Implementation

This program uses a decoding algorithm that works as follows:

  1. We maintain the encoding table as a data structure in JavaScript.
  2. We read the binary sequence from the beginning and by examining characters, we try to identify the longest possible sequence that matches one of the codes.
  3. After identifying a code, we add its equivalent character to the result string.
  4. We continue this process until the entire binary sequence is processed.