views:

112

answers:

1

I'm looking for av way to convert a string into whitespace; spaces, newlines and tabs, and the other way around.

I found a Python script, but I have no idea how to do it using Javascript.

I need it for a white-hacking contest.

+1  A: 

I can has banana? ;)

var ws={x:'0123',y:' \t\r\n',a:/[\w\W]/g,b:/[\w\W]{8}/g,c:function(z){return(
ws.y+ws.x)[(ws.x+ws.y).indexOf(z)]},e:function(s){return(65536+s.charCodeAt(0)
).toString(4).substr(1).replace(ws.a,ws.c)},d:function(s){return String.
fromCharCode(parseInt(s.replace(ws.a,ws.c),4))},encode:function(s){return s.
replace(ws.a,ws.e)},decode:function(s){return s.replace(ws.b,ws.d)}};

// test string
var s1 = 'test0123456789AZaz€åäöÅÄÖ';

// show test string
alert(s1);

// encode test string
var code = ws.encode(s1);

// show encoded string
alert('"'+code+'"');

// decode string
var s2 = ws.decode(code);

// show decoded string
alert(s2);

// verify that the strings are completely identical
alert(s1 === s2);
Guffa
Here is your well deserved virtual banana: http://1.bp.blogspot.com/_OrYGtRC--A8/SdridW5_VrI/AAAAAAAAC0o/x2ZPw26fZiM/s400/Giant%2Bbanana.jpg enjoy :D Could you please explain the first part of the code? and why minified? makes it so hard to read. I want to learn from this.
mofle