Skip to content

Instantly share code, notes, and snippets.

@aarongeorge
Last active April 6, 2020 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aarongeorge/9c6495a49304b85d6008104e84ad824c to your computer and use it in GitHub Desktop.
Save aarongeorge/9c6495a49304b85d6008104e84ad824c 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 = t => t.split('').map(c => (`0${c.charCodeAt(0).toString(16)}`).slice(-2)).join(' ')
const hexToControlCharacter = h => h.split(' ').map(c => 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