messagescramble: A Lightweight Text Scrambler Inspired by CODE100
Back at this years’ World Congress, Nimrod Kor took home the CODE100 trophy after providing a slick solution for our final challenge. We were so impressed by his approach, in fact, that Nimrod joined us to talk through his solution.
With this in mind, the mastermind behind the challenge, our VP of DevRel Chris Heilmann decided to turn it into an npm package called messagescramble, providing a fun and easy way to scramble and unscramble text using a key sentence, making it perfect for puzzles or even lightweight obfuscation.
How It Works
- You provide a key sentence.
- The package builds a character-to-index map from that key, so each letter is assigned a number.
encode
turns your message into a sequence of numbers, with random letters for obfuscation.decode
reverses the process back to readable text, when the key is correct.
A Quick Example
// Import the package after installation
import { encode, decode } from "messagescramble";
// The key we have used contains every letter of the alphabet
const key = "the quick brown fox jumps over the lazy dog";
const message = "hello world";
// Encode
const encoded = encode(message, key);
console.log(encoded.message); // scrambled numbers
// Decode
const decoded = decode(encoded.message, key);
console.log(decoded.message); // "hello world"
Try It Yourself
If you’d like to see the package in action, go and check out the demo page, read more on the npm site or simply run npm i messagescramble
to install it and get going right away.