function rot13(str) {
var num = [];
for(var i=0; i<str.length; i++){
num.push(str.charCodeAt(i));
}
var num2 = num.map( function(value) {
//A to Z is between 65 and 90 so only convert these values
if(value>=65 && value<=90){
if(value-13 >= 65){
return value - 13;
} else {
return value + 13;
}
} else {
return value;
}
});
var num3 = [];
for(var j=0; j<num2.length; j++){
num3.push(String.fromCharCode(num2[j]));
}
return num3.join('');
}
No comments:
Post a Comment