Skip to content

Instantly share code, notes, and snippets.

@aemkei
Forked from 140bytes/LICENSE.txt
Created October 26, 2011 19:17
Show Gist options
  • Save aemkei/1317480 to your computer and use it in GitHub Desktop.
Save aemkei/1317480 to your computer and use it in GitHub Desktop.
Leet - 140byt.es

Leet - 140byt.es

Converts a latin character string into leetspeak.

Example output

140By7.35 15 4 7w337-51z3D, F0RK-70-PL4y, C0MMuN17y-CuR473D 
C0LL3C710N 0F J4v45CR1P7. 60 70 7H3 M4573R 6157 P463, 4ND 
CL1CK 7H3 Bu770N. 1. M0D1Fy 4LL 7H3 F1L35 70 4CC0RD1N6 70 
7H3 RuL35 1N 7H3 6157. 2. 54v3 y0uR 3N7Ry 4ND 7w337 17 uP! 
3. K33P 1N M1ND 7H47 7H4NK5 70 7H3 4w350M3 53N51B1L17135 0F 
7H3 617HuB 734M, 61575 4R3 Ju57 R3P05. 50 F33L FR33 70 CL0N3 
y0uR5 4ND w0RK L0C4LLy F0R 4 M0R3 C0MF0R74BL3 3Nv1R0NM3N7, 
4ND 70 4LL0w C0MM17 M3554635.

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function f( // callback for replace
a // input string or character to replace
){
return "4BCD3F6H1JKLMN0PQR57"[
parseInt(a, 36) // get code of character
-10 // shift "A" to 0
] || a.replace( // replace characters in input string
/[a-t]/gi, // ignore case
f
)
}
function f(a){return"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a.replace(/[a-t]/gi,f)}
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.
{
"name": "leet",
"description": "Converts a latin character string into leetspeak.",
"keywords": [
"string",
"1337",
"ascii"
]
}
<!DOCTYPE html>
<title>Leet 140byt.es</title>
<style>
#output { font-family: monospace; width: 400px; font-size: 16px;}
#input { width: 400px; height: 30px; display: block;}
button { margin: 1em 0;}
</style>
<textarea id="input">
140byt.es is a tweet-sized, fork-to-play, community-curated collection of JavaScript.
Go to the master gist page, and click the button.
1. Modify all the files to according to the rules in the gist.
2. Save your entry and tweet it up!
3. Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.
</textarea>
<button onclick="convert()">-> LEET -></button>
<div id="output"></div>
<script>
var leet = function f(a){return"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a.replace(/[a-t]/gi,f)}
function convert(){
document.getElementById( "output" ).innerHTML = leet(document.getElementById( "input" ).value);
}
convert();
</script>
@aemkei
Copy link
Author

aemkei commented Oct 27, 2011

Does anyone knows how I can get rid of b or c?
I use c to check if we are in the replace method or not.

@subzey
Copy link

subzey commented Oct 27, 2011

We can use parseInt(str,36), it's case-insensitive and covers all letters of english alphabet:

function f(a,b,c){return c?"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a:a.replace(/./g,f)}

@atk
Copy link

atk commented Oct 27, 2011

Since b is 0 (false-y) at the first call of the replace, we can't use it. ~b doesn't help either, because undefined gets coerced, too on this one.k Additionally, we can achieve IE compatibility using only 5bytes more, by replacing "4BCD3F6H1JKLMN0PQR57" with [4,,,,3,,6,,1,,,,,,,,,,5,7].

Update: We can use ++b and save 1 char:

function f(a,b){return++b?"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a:a.replace(/./g,f)}

@tsaniel
Copy link

tsaniel commented Oct 28, 2011

What about

function f(a,b){return"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a.replace(/[a-t]/gi,f)}
```?

@aemkei
Copy link
Author

aemkei commented Oct 28, 2011

So we don't need banymore:

function f(a){return"4BCD3F6H1JKLMN0PQR57"[parseInt(a,36)-10]||a.replace(/[a-t]/gi,f)}

Down to 86 bytes!

@tsaniel
Copy link

tsaniel commented Oct 28, 2011

600D C47CH, @aemkei!
It seems that converting a leetspeak character string into latin is more difficult?

@aemkei
Copy link
Author

aemkei commented Oct 28, 2011

@tsaniel: I think it is impossible to translate leet back to latin, because the numbers 436157are used here.
So 140By7.35 would be converted to 1A0BY.TES.

@aemkei
Copy link
Author

aemkei commented Oct 31, 2011

Hey @tsaniel, @atk, and @subzey,
I'm trying to get hsl2rgb down but still have to save 10 bytes.

Can you help me out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment