Skip to content

Instantly share code, notes, and snippets.

@david-thorman
Forked from denmojo/lolol_converter.html
Last active August 29, 2015 14:22
Show Gist options
  • Save david-thorman/802731962c11b290c84d to your computer and use it in GitHub Desktop.
Save david-thorman/802731962c11b290c84d to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LOLOL Encoder/Decoder</title>
<script type="text/javascript">
//<![CDATA[
function lolol2txt(lolol)
{
// Gets a lolol encoded string, removes leading "l" and converts to ascii text
var string = "";
lolol = lolol.trim();
if(lolol.length%8 == 1) // in case there's no leading "l"
lolol = lolol.substring(1);
lolol = lolol.toLowerCase();
binary = lolol.replace(/l/g, '1');
binary = binary.replace(/o/g, '0');
if(binary.length%8 != 0){
alert("Not valid encoded lolol.");
return -1;
}
for(i=0; i<binary.length/8; i++){
sub = binary.substr(i*8, 8);
num = 0;
for(j=0; j<sub.length; j++){
if(sub.charAt(j) == '0'){
}
else{
num += Math.pow(2, 7-j);
}
}
string += String.fromCharCode(num);
}
document.getElementsByName('string1')[0].value = string
}
function ascii_value(c){
c = c.charAt(0);
var i;
for (i=0; i<256; i++){
var h = i.toString(16);
if(h.length == 1)
h = "0"+h;
h = "%"+h;
h = unescape(h);
if(h == c)
break;
}
return i;
}
function txt2lolol(string)
{
// Creates a lolol-encoded string from binary, adding a leading "l"
var binary = "";
var lolol = "l";
for(i=0; i<string.length; i++){
char = ascii_value(string.charAt(i));
num = "";
for(j=7; j>=0; j--){
if(Math.pow(2, j) <= char){
num += "1";
char -= Math.pow(2, j);
}
else{
num += "0";
}
}
binary += ""+num;
}
lolol += binary.replace(/1/g, 'l');
lolol = lolol.replace(/0/g, 'o');
document.getElementsByName('binary')[0].value = lolol;
return lolol;
}
function makeUppercase() {
document.getElementsByName('binary')[0].value = document.getElementsByName('binary')[0].value.toUpperCase();
}
//]]>
</script>
</head>
<body>
<h3>LOLOL encoder/decoder</h3>
<form action="">
<textarea rows="4" cols="80" name="string1"></textarea><br />
<input type="button" value="To lolol" onclick=
"txt2lolol(document.getElementsByName('string1')[0].value)" />&nbsp; <input type=
"button" value="Uppercase It" onclick="makeUppercase()" /><br />
<textarea rows="4" cols="80" name="binary"></textarea><br />
<input type="button" value="To Text" onclick=
"lolol2txt(document.getElementsByName('binary')[0].value)" /><br />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment