Skip to content

Instantly share code, notes, and snippets.

@6220119
Forked from xem/LICENSE.txt
Created January 22, 2021 03:08
Show Gist options
  • Save 6220119/d4154098c629d4e6b0729e5286ce54ff to your computer and use it in GitHub Desktop.
Save 6220119/d4154098c629d4e6b0729e5286ce54ff 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