小编unl*_*cky的帖子

JavaScript 中的凯撒密码

我正在尝试编写一个程序来解决javascript中的以下问题(写在本段下面)。我不知道为什么我的代码不起作用。有人可以帮助我吗?我是 JavaScript 新手;这是一个免费的代码训练营问题。

\n\n

“现代常见的用法是 ROT13 密码,其中字母的值移动 13 位。因此 \'A\' \xe2\x86\x94 \'N\'、\'B\' \xe2\x86\ x94\'O\' 等等。

\n\n

编写一个函数,将 ROT13 编码字符串作为输入并返回解码后的字符串。”

\n\n

\r\n
\r\n
function rot13(str) { // LBH QVQ VG!\r\n  \r\n  var string = "";\r\n  for(var i = 0; i < str.length; i++) {\r\n    var temp = str.charAt(i);\r\n    if(temp !== " " || temp!== "!" || temp!== "?") {\r\n       string += String.fromCharCode(13 + String.prototype.charCodeAt(temp));\r\n    } else {\r\n      string += temp;\r\n    }\r\n  }\r\n  \r\n  return string;\r\n}\r\n\r\n// Change the inputs below to test\r\nconsole.log(rot13("SERR …
Run Code Online (Sandbox Code Playgroud)

javascript caesar-cipher

6
推荐指数
2
解决办法
5万
查看次数

标签 统计

caesar-cipher ×1

javascript ×1