Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.2 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
56533eb9ac21ba0edf2244e2 凯撒密码 5 16003 caesars-cipher

--description--

凯撒密码是最简单且最广为人知的密码,也被称为移位密码。在移位密码中,明文中的字母通过按照一个固定数目进行偏移后被替换成新的字母。

ROT13 是一个被广泛使用的加密技术,明文中的所有字母都被移动 13 位。因此有:'A' ↔ 'N'、'B' ↔ 'O' 等等。

请编写一个函数,用于解码一个被 ROT13 编码的字符串,然后返回解码后的结果。

所有解码后的字母都必须为字母大写。请不要解码非字母的字符(例如,空格、标点符号),但你需要在结果中保留它们。

--hints--

rot13("SERR PBQR PNZC") 应解码为 FREE CODE CAMP

assert(rot13('SERR PBQR PNZC') === 'FREE CODE CAMP');

rot13("SERR CVMMN!") 应解码为 FREE PIZZA!

assert(rot13('SERR CVMMN!') === 'FREE PIZZA!');

rot13("SERR YBIR?") 应解码为 FREE LOVE?

assert(rot13('SERR YBIR?') === 'FREE LOVE?');

rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") 应解码为 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.

assert(
  rot13('GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.') ===
    'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'
);

--seed--

--seed-contents--

function rot13(str) {

  return str;
}

rot13("SERR PBQR PNZC");

--solutions--

var lookup = {
  'A': 'N','B': 'O','C': 'P','D': 'Q',
  'E': 'R','F': 'S','G': 'T','H': 'U',
  'I': 'V','J': 'W','K': 'X','L': 'Y',
  'M': 'Z','N': 'A','O': 'B','P': 'C',
  'Q': 'D','R': 'E','S': 'F','T': 'G',
  'U': 'H','V': 'I','W': 'J','X': 'K',
  'Y': 'L','Z': 'M'
};

function rot13(encodedStr) {
  var codeArr = encodedStr.split("");  // String to Array
  var decodedArr = []; // Your Result goes here
  // Only change code below this line

  decodedArr = codeArr.map(function(letter) {
    if(lookup.hasOwnProperty(letter)) {
      letter = lookup[letter];
    }
    return letter;
  });

  // Only change code above this line
  return decodedArr.join(""); // Array to String
}