Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROT13 #5

Open
soonlive opened this issue Oct 8, 2016 · 0 comments
Open

ROT13 #5

soonlive opened this issue Oct 8, 2016 · 0 comments

Comments

@soonlive
Copy link
Owner

soonlive commented Oct 8, 2016

ROT13

Description:

How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.

I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it? According to Wikipedia, ROT13 (http://en.wikipedia.org/wiki/ROT13) is frequently used to obfuscate jokes on USENET.

Hint: For this task you're only supposed to substitue characters. Not spaces, punctuation, numbers etc. Test examples:

Test.expect(rot13("EBG13 rknzcyr.") == "ROT13 example.");
Test.expect(rot13("This is my first ROT13 excercise!") == "Guvf vf zl svefg EBG13 rkprepvfr!")

题意:

将字符串中的字母替换为在26个字母表中向右移动13个位置后的字母,区分大小写

Solution:

function rot13(str) {
  return str.split('').map(function (n) {
      if(/[A-Za-z]/.test(n)){
          var charCode = n.charCodeAt(0);
          n = String.fromCharCode(charCode>109 || (charCode>77 && charCode<91)?charCode-13:charCode+13);
      }
      return n;
  }).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant