Name: Anonymous 2011-10-11 19:06
I am a self-taught programmer and here are my codes for generalized rot13:
perl:
python:
javascript:
Your comments are welcome. Feel free to guess my sex, age and sexual orientation :-)
perl:
sub rot{($_,$n)=@_;$a=join("","a".."z");$t=substr($a,$n).substr($a,0,$n-1);$T=uc($t);eval("tr/a-zA-Z/$t$T/");$_}python:
def rot(x, n):
r = lambda c, ord_a: chr(ord_a + (ord(c) - ord_a + n)%26)
return ''.join(map(lambda c:(c>='a' and c<='z') and r(c, 97) or (c>='A' and c<='Z') and r(c, 65) or c, x))javascript:
function rot(x, n){
var r = function(c, ord_a){ return String.fromCharCode(ord_a + (c.charCodeAt(0) - ord_a + n)%26) };
var r2 = function(c){ return (c>="a" && c<="z") ? r(c, 97) : (c>="A" && c<="Z") ? r(c, 65) : c };
return x.split("").map(r2).join("")
}Your comments are welcome. Feel free to guess my sex, age and sexual orientation :-)