Javascript/JScript: 72 to 105 chars
Here is a Javascript/JScript attempt at making a version of this code.
I'm aware that there is another Javascript code, but that one relies on recent Javascript implementations.
That is a bad thing!!!
That code is invalid in ie8< without polyfills.
Here is my version:
function $(c){for(var i=0,l=c.length,o='';i<l;o+=String.fromCharCode(c.charCodeAt(i++)+i&255));return o;}
//function call, 105 chars, absolutely valid!
function $(c){for(i=0,l=c.length,o='';i<l;o+=String.fromCharCode(c.charCodeAt(i++)+i&255));return o;}
//function call, no var keyword, 101 chars, completely valid!
function $(c){for(i=0,l=c.length,o='';i<l;o+=String.fromCharCode(c.charCodeAt(i++)+i));return o;}
//function call, 97 chars, most likely invalid!
c='';//here goes input, output is in var `o`, dont count this line
for(i=0,l=c.length,o='';i<l;o+=String.fromCharCode(c.charCodeAt(i++)+i&255));
//no function call, input goes to var c, 77 chars of pure working code! valid for sure!
c='';//here goes input, output is in var `o`, dont count this line
for(i=0,l=c.length,o='';i<l;o+=String.fromCharCode(c.charCodeAt(i++)+i));
//no function call, input goes to var c, no char wrapping after 255, 73 chars of probably invalid code
@toothbrush gave me this answer:
i=0;while(i<c.length)c[i]=String.fromCharCode(c.charCodeAt(i++)+i%255+1)
It changes the original string and is only 72 bytes!
I don't know why he has %255+1
in the end when &255
does the same job, is faster and shorter.
But I will keep the original answer intact.
Consider this and test it with a Javascript/JScript interpreter.
I know that the 73 char version and the 97 char function call version will be invalid, but its still here!
If you will be using the code in a production environment (website), use the 105 chars long and consider changing the function name to something else (or you might have problems with jQuery and MooTools).