Skip to content

Instantly share code, notes, and snippets.

@HaiBV
Created November 13, 2019 10:37
Show Gist options
  • Save HaiBV/bfe34e0e7a96d412974b02ac14e1f81f to your computer and use it in GitHub Desktop.
Save HaiBV/bfe34e0e7a96d412974b02ac14e1f81f to your computer and use it in GitHub Desktop.
messageFromBinaryCode
function messageFromBinaryCode(code) {
return code.match(/.{8}/g).reduce((a,b)=>a+String.fromCharCode(parseInt(b,2)),"")
}
@HaiBV
Copy link
Author

HaiBV commented Nov 13, 2019

You are taking part in an Escape Room challenge designed specifically for programmers. In your efforts to find a clue, you've found a binary code written on the wall behind a vase, and realized that it must be an encrypted message. After some thought, your first guess is that each consecutive 8 bits of the code stand for the character with the corresponding extended ASCII code.

Assuming that your hunch is correct, decode the message.

Example

For code = "010010000110010101101100011011000110111100100001", the output should be
messageFromBinaryCode(code) = "Hello!".

The first 8 characters of the code are 01001000, which is 72 in the binary numeral system. 72 stands for H in the ASCII-table, so the first letter is H.
Other letters can be obtained in the same manner.

https://app.codesignal.com/arcade/intro/level-12/sCpwzJCyBy2tDSxKW/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment