Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PERCE-NEIGE/f20ff3e5b5b6dc5e176fd41d538edd41 to your computer and use it in GitHub Desktop.
Save PERCE-NEIGE/f20ff3e5b5b6dc5e176fd41d538edd41 to your computer and use it in GitHub Desktop.
A code generator that takes Javascript and compiles it to ASCII Control Characters that are not visible, based on Martin Kleppe's "Invisible Code" talk
/**
* Invisible Code Generator
*
* Description:
* A code generator that takes Javascript and compiles it to
* ASCII Control Characters that are not visible
*
* Usage:
* Copy and paste the code into your browsers console
* Then paste the code you wish to convert to "Invisible Code"
* Your code will then be copied to your clipboard
*
* Credits: Martin Kleppe aka @aemkei
*
* Author: Aaron George
* Github: github.com/aarongeorge
*/
const textToHex = (text) => {
return text.split('').map((c) => {
return (`0${c.charCodeAt(0).toString(16)}`).slice(-2);
}).join(' ');
};
const hexToControlCharacter = (hex) => {
return hex.split(' ').map((c) => {
return c.replace(/(.)(.)/, '%1$1%1$2');
}).join('');
};
const codeToHide = window.prompt('Enter your code');
const hex = textToHex(codeToHide, ' ');
const cc = unescape(hexToControlCharacter(hex));
// Copy text to clipboard
copy(`eval(eval('"'+escape("${cc}").replace(/..(.)..(.)/g,'\\\\x$1$2')+'"'))`);
// Alert that the text is there
window.alert('Code has been copied to your clipboard');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment