Skip to content

Instantly share code, notes, and snippets.

@kolodny
Forked from xem/LICENSE.txt
Last active August 27, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolodny/7c03e8bf4c158a040255 to your computer and use it in GitHub Desktop.
Save kolodny/7c03e8bf4c158a040255 to your computer and use it in GitHub Desktop.
Challenge: Executing more than 140 JS characters in a tweet!

Hello

This fork isn't really a 140bytes entry, but a challenge!

What if a tweet (140 utf-16 characters) could execute more than 140 characters of JavaScript code?

190 chars:

thanks to subzey's help, a tweet can execute 190 js chars.

Encoder:

z=function(b,c,a,f){c="";f=String.fromCharCode;for(a=0;190>a;a+=2)c+=f(55296+b.charCodeAt(a))+f(56320+b.charCodeAt(a+1));return c}

Decoder / Executer (140 chars): (replace xxxx with your encoded JS string)

eval(unescape(escape("xxxx").replace(/uD./g,'')))

Demo:

http://jsfiddle.net/99GVk/1/

// Encoder:
// @param b: the input code (198 chars)
z = function(b, c, a, f){
// The encoded string begins with "'"
c = "";
// Shortcut
f = String.fromCharCode;
// Loop through the input code
for(a = 0; 190 > a; a += 2){
// Create and append an UTF-16 surrogate pair, containing the ASCII codes at b[a] and b[a+1] in each half's last 7 bits
c += f(55296 + b.charCodeAt(a)) + f(56320 + b.charCodeAt(a + 1));
}
// return the encoded string
return c
}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment