Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
Created June 27, 2012 18:03
Show Gist options
  • Save gialloporpora/3005731 to your computer and use it in GitHub Desktop.
Save gialloporpora/3005731 to your computer and use it in GitHub Desktop.
A joke to show in a funy way a binary encrypted string. It works better with strings of 7 characters
Number.prototype.toBinary=function(width, zero, one){
var b=this.toString(2);
var zeroString = '';
if (width) if ((width-b.length)>0) zeroString = Math.pow(10,width-b.length).toString().substr(1);
var output = zeroString + b;
if ((zero) && (one)) {
if (typeof(zero)=='number') zero=String.fromCharCode(zero);
if (typeof(one)=='number') one=String.fromCharCode(one);
output = output.replace(/0/g,zero);
output = output.replace(/1/g,one);
}
return output;
}
String.prototype.magicBox=function(zero, one){
if (!(zero)) zero='0';
if (!(one)) one='1';
s='';
for (i=0; i<this.length; i++) s+= this.charCodeAt(i).toBinary(this.length, zero,one)+'\n';
return s;
}
alert('*Magic*'.magicBox(9734,9733));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment