Created
November 22, 2019 07:08
-
-
Save 410063005/77770124bf86f1e4de18d036e4e2155c to your computer and use it in GitHub Desktop.
凯撒密码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.freecodecamp.cn/challenges/caesars-cipher | |
function rot13(str) { // LBH QVQ VG! | |
// 请把你的代码写在这里 | |
var a = 'A'.charCodeAt(); | |
var z = a + 25; | |
var r = []; | |
for (var i = 0; i < str.length; i++) { | |
var code = str[i].charCodeAt(); | |
if (code >= a && code <= z) { | |
var code2 = code + 13; | |
if (code2 > z) { | |
code2 -= 26; | |
} | |
r.push(String.fromCharCode(code2)); | |
} else { | |
r.push(str[i]); | |
} | |
} | |
str = r.join(''); | |
return str; | |
} | |
rot13("SERR PBQR PNZC"); // 你可以修改这一行来测试你的代码 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment