codecamp

位移密码算法挑战

function rot13(str) { // LBH QVQ VG!
    var cipher=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
    var rot = "";
    for(var i = 0; i < str.length; i++){
        var index = -1 ;
        index = cipher.indexOf(str[i]);
        if( index >= 0 ){
            rot +=  cipher[(index + 13) % 26];
        }else{
            rot += str[i];
        }
    }
    return rot;
}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
数组排序并插入值算法挑战
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }