Skip to content

Instantly share code, notes, and snippets.

@IngwiePhoenix
Created February 25, 2020 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IngwiePhoenix/501942963259da21def4a6fe0cc1f36a to your computer and use it in GitHub Desktop.
Save IngwiePhoenix/501942963259da21def4a6fe0cc1f36a to your computer and use it in GitHub Desktop.
AEW's "cryptic" Dark Order message - decrypted. (Although...not that hard.)

AEW Cryptic Tweet translation

The following files all contain material used for conversion. I was bored so I wrote this tiny program as a way to warm up before working on some PHP and Laravel stuff.

I used NodeJS. The code is provided below.

If you want the output, scroll to the last file at the bottom.

Tested on NodeJS 13.9.0!

Thanks for reading! :)

Challenge

Feel bored? Optimize my code! :)

Find me

Twitter: @IngwiePhoenix

# Copy-typed off the WhatCulture #ThisIsTheNews evening video,
# which showed the tweet: https://www.youtube.com/watch?v=dliynTh6CfI
01001010 01000100 01001111
01001111 01000001 01010010
01001001 01010010 01000100
01001110 01001011 01000101
01010010
const {readFileSync, existsSync} = require("fs");
const {fromCodePoint} = String;
const {argv} = process;
const {error, log} = console;
const {write} = process.stdout;
if(argv.length != 3) {
error("Please supply the input file.");
}
const filename = argv[2];
if(!existsSync(filename)) {
error(`File "${filename}" not found!`);
}
let contents = readFileSync(filename).toString("utf8");
// Although I have sanity checks above, I am only going to ignore comments,
// and not make any further checks. This is just a silly little tool anyway.
let lines = contents.split("\n");
lines.forEach(line => {
if(line.trim().startsWith("#")) return;
/*
Because I am lazy, I am going to artificially pad a space here to make the loop
below actually print out the third found set of digits in ASCII.
There are highly likly better methods to do so but it's 11.19pm and...well, this
is not a serious program at all.
So f*ck it, I'll cheat. xD
*/
let chars = (line+" ").split("");
let bin = "";
let newLine = [];
let skipCount = 0;
let seenNumbersYet = false;
for(let i in chars) {
let char = chars[i]; // Nope, not gonna do .hasOwnProperty, cuz im lazy.
if(char == "0" || char == "1") {
bin += char;
seenNumbersYet = true;
} else if(char == " " && seenNumbersYet) {
newLine.push(fromCodePoint(parseInt(bin, 2)));
bin = "";
} else if(char == " " && !seenNumbersYet) {
skipCount++;
}
}
// Number.times() isn't exactly a method so...
for(var j = ((skipCount - (skipCount % 8)) / 8); j != 0; j--) {
newLine.unshift(" ");
}
log(newLine.join(" "));
});
> node .\aew-decrypt.js .\aew-msg.txt
J D O
O A R
I R D
N K E
R
@andersevenrud
Copy link

andersevenrud commented Feb 25, 2020

Here's a functional approach with one long chain 😊

Edit See updated answer below

const result = require('fs')
  .readFileSync(process.argv[2], 'utf8')
  .trim()
  .split('\n')
  .map(str => str.trim())
  .filter(str => str.substr(0, 1) !== '#')
  .map(str => str
    .split(' ')
    .map(str => String.fromCodePoint(parseInt(str, 2))))
    .map((group, index, arr) => group.join(' ').padStart((arr[0].length * 2) - 1, ' '))
  .join('\n')

console.log(result)

Annotated:

const result = require('fs')
  .readFileSync(process.argv[2], 'utf8')

  // Split into lines only containing the binary
  .trim()
  .split('\n')
  .map(str => str.trim())
  .filter(str => str.substr(0, 1) !== '#')

  // Turn each line into groups
  .map(str => str
    // Split each group of binary and convert to character
    .split(' ')
    .map(str => String.fromCodePoint(parseInt(str, 2))))

    // Concatenates groups of characters back into a string preserving the length of the first entry (padding)
    .map((group, index, arr) => group.join(' ').padStart((arr[0].length * 2) - 1, ' '))

  // Finally turn back into a block of text
  .join('\n')

console.log(result)

@IngwiePhoenix
Copy link
Author

@andersevenrud Thank you man! That is some freaking awesome way of doing this. I totally forgot about .map and .filter on strings. Man, I learned a lot there!

@andersevenrud
Copy link

Thanks for the challenge!

Whenever faced with a text parsing problem the Array higher order functions can be really powerful 🤘

@andersevenrud
Copy link

andersevenrud commented Feb 26, 2020

I realized this could be flattened quite a bit, making it more readable :)

const result = require('fs')
  .readFileSync(process.argv[2], 'utf8')
  .trim()
  .split('\n')
  .map(str => str.trim())
  .filter(str => str.substr(0, 1) !== '#')
  .map(str => str.split(' '))
  .map(group => group.map(str => String.fromCodePoint(parseInt(str, 2))))
  .map(group => group.join(' '))
  .map((str, index, arr) => str.padStart(arr[0].length, ' '))
  .join('\n')

console.log(result)

Annotated:

const result = require('fs')
  .readFileSync(process.argv[2], 'utf8')

  // Split into lines only containing the binary
  .trim()
  .split('\n')
  .map(str => str.trim())
  .filter(str => str.substr(0, 1) !== '#')

  // Turn each line into groups
  .map(str => str.split(' '))

  // Split each group of binary and convert to character
  .map(group => group.map(str => String.fromCodePoint(parseInt(str, 2))))

  // Concatenates groups of characters back into a string
  .map(group => group.join(' '))

  // Makes all strings padding the same as the first entry
  .map((str, index, arr) => str.padStart(arr[0].length, ' '))

  // Finally turn back into a block of text
  .join('\n')

console.log(result)

@IngwiePhoenix
Copy link
Author

@andersevenrud You sure enjoy that little challenge. :p Glad to learn something new! This sure looks waaaaaay better than my initial approach. Almost makes me feel like a "script kiddy" in comparsion... xD

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