Skip to content

Instantly share code, notes, and snippets.

@liath
Created August 25, 2018 00:33
Show Gist options
  • Save liath/1c0173ca14bf73476a52131eec736160 to your computer and use it in GitHub Desktop.
Save liath/1c0173ca14bf73476a52131eec736160 to your computer and use it in GitHub Desktop.
Darknet 7: Krux's Silk Screen Challenge
/* This script will attempt to brute force any pollux ciphertext you hand it.
Most of the output is useless but for every ciphertext I could create on
[dcode](https://www.dcode.fr/pollux-cipher), it had the correct result in its
output somewhere. Usually towards the middle. Unfortunately it does not give
any useful results for the actual challenge. ¯\_(ツ)_/¯ */
/* eslint no-console:0, no-param-reassign:["error", { "props": false }] */
/* eslint-disable sort-keys */
const morse2char = {
'.-': 'a',
'-...': 'b',
'-.-.': 'c',
'-..': 'd',
'.': 'e',
'..-.': 'f',
'--.': 'g',
'....': 'h',
'..': 'i',
'.---': 'j',
'-.-': 'k',
'.-..': 'l',
'--': 'm',
'-.': 'n',
'---': 'o',
'.--.': 'p',
'--.-': 'q',
'.-.': 'r',
'...': 's',
'-': 't',
'..-': 'u',
'...-': 'v',
'.--': 'w',
'-..-': 'x',
'-.--': 'y',
'--..': 'z',
'.----': '1',
'..---': '2',
'...--': '3',
'....-': '4',
'.....': '5',
'-....': '6',
'--...': '7',
'---..': '8',
'----.': '9',
'-----': '0',
'..--.-': '_',
'-....-': '-',
'--..--': ',',
'-.-.-.': ';',
'---...': ':',
'..--..': '?',
'.-.-.-': '.',
'.----.': '\'',
'.-..-.': '"',
'-.--.': '(',
'-.--.-': ')',
'-..-.': '/',
'.-.-.': '+',
'-...-': '=',
'...-..-': '$',
' ': ' ',
'': ' ',
};
/* eslint-enable sort-keys */
// DCODEPOLLUX
// const ciphertext = '1709434021559587989345091149340868137288495381';
// badge text
const ciphertext = '010630746104';
const test = lookup => {
let morse = [...ciphertext].map(x => lookup[x]);
morse = morse.join('');
morse = morse.split(' ').filter(x => x !== '');
morse = morse.map(x => morse2char[x]);
if (morse.some(x => x === undefined)) return false;
morse = morse.join('');
return morse;
};
const morseSymbols = ['-', '.', ' '];
const cipherSymbols = Object.keys([...ciphertext].reduce((s, x) => {
s[x] = true;
return s;
}, {}));
let results = [];
for (let i = 0; i < (morseSymbols.length ** cipherSymbols.length); i++) {
const lookup = cipherSymbols.reduce((s, x, j) => {
s[x] = morseSymbols[Math.floor(i / (morseSymbols.length ** j)) % morseSymbols.length];
return s;
}, {});
const ret = test(lookup);
if (ret) results.push(ret);
}
// remove any duplicate entries
results = Object.keys(results.reduce((s, x) => {
s[x] = true;
return s;
}, {}));
console.log(`Found ${results.length} potential solutions:`);
results.forEach(x => {
console.log(x);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment