位移密碼算法挑戰(zhàn)

2018-07-05 11:47 更新
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");
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號