Public Solving: Decoding a secret message

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Shorter version
String.fromCharCode(parseInt(str, 2).toString(10));
Example -: https://jsfiddle.net/b81axeju/
I solved it! It's "Jingle bells" haha 😂 Merry Christmas to you in advance, Chris!
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Santa got a super weird email, and at first, he thought he might have been hacked.
But it was just a cool hacker kid not wanting the public to see his letter to Santa.
But Santa doesn't know much about computers and asked us to decode the message he received.
You can find the complete puzzle here.
Let's first look at what we get. There seems to be a message that looks kind of like this:
01001010
01101001
01101110
01100111
01101100
01100101
00100000
01100010
01100101
01101100
01101100
01110011
If you've been through any basic computer science class you might have spotted this is binary code.
Something your computer uses underwater because it only knows ones and zeros.
Knowing this, we can see each line is actually a specific symbol. This could be a letter, symbol, number, or space.
Let's get right into solving this problem so we can feel like Ackerman.

The first thing we want to do is make sure we can access all the individual lines.
Knowing they are all on different lines, we can use the split method to split on a new line like so.
input.split('\n')
This will give us an array of binary codes.
And seeing it's now an array, we can use the all-around excellent reduce method.
return input.split('\n').reduce((string, binary) => {
// todo
}, '');
The reduce takes two arguments: the accumulator (string) and the current looped element (binary).
We set the accumulator default value at the end, and I set it as an empty string.
We need to return the string and append the decoded symbol for this binary code inside.
To decode a binary code, we can use the following JavaScript function.
String.fromCharCode(parseInt(binary, 2))
Two things are happening there:
parseInt: This piece will convert the binary code to a character code. String.fromCharCode converts the character code to a string.Let's take the following binary code and see what happens:
const binary = '01001010'
const charCode = parseInt(binary, 2)
// 74
const symbol = String.fromCharCode(charCode)
// J
Meaning that this binary range is the letter J.
Now let's use this and combine it into the reduce function.
return input.split('\n').reduce((string, binary) => {
return (string += String.fromCharCode(parseInt(binary, 2)));
}, '');
And that's it! We now have a binary decoder in JavaScript 😎.
Look at us being hackers.
There is only one more thing to do, Run the tests.

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter