Complete Caesar's Cipher
This commit is contained in:
@ -4436,29 +4436,61 @@
|
||||
"title": "Caesar's Cipher",
|
||||
"description": [
|
||||
"One of the simplest and most widely known <dfn>ciphers</dfn> is a <code>Caesar cipher</code>, also known as a <code>shift cipher</code>. In a <code>shift cipher</code> the meanings of the letters are shifted by some set amount. ",
|
||||
"A common modern use is a <a href=\"https://en.wikipedia.org/wiki/ROT13\">ROT13</a> cipher, where the values of the letters are shifted by 13 places. Thus A = N, B = O and so on.",
|
||||
"Write a function which takes a <code>ROT13</code> encoded array of characters as input and returns a plain text encoded array. All letters will be uppercase. Do not transform any non-alphabetic character (IE: spaces, punctiation)."
|
||||
"A common modern use is the <a href=\"https://en.wikipedia.org/wiki/ROT13\">ROT13</a> cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.",
|
||||
"Write a function which takes a <code>ROT13</code> encoded string as input and returns a decoded string. All letters will be uppercase. Do not transform any non-alphabetic character (IE: spaces, punctiation), but do pass them on.",
|
||||
"The provided code transforms the input into an array for you, <code>codeArr</code>. Place the decoded values into the <code>decodedArr</code> array where the provided code will transform it back into a string."
|
||||
],
|
||||
"releasedOn": "11/27/2015",
|
||||
"tests": [
|
||||
"assert( rot13([ 'S', 'E', 'R', 'R', ' ', 'P', 'B', 'Q', 'R', ' ', 'P', 'N', 'Z', 'C' ]).join(\"\") === \"FREE CODE CAMP\", 'message: <code>rot13([ 'S', 'E', 'R', 'R', ' ', 'P', 'B', 'Q', 'R', ' ', 'P', 'N', 'Z', 'C' ])</code> should decode to <code>[ 'F', 'R', 'E', 'E', ' ', 'C', 'O', 'D', 'E', ' ', 'C', 'A', 'M', 'P' ]</code>');",
|
||||
"assert(1===1, 'message: blah');"
|
||||
"assert(rot13(\"SERR PBQR PNZC\") === \"FREE CODE CAMP\", 'message: <code>rot13(\"SERR PBQR PNZC\")</code> should decode to <code>\"FREE CODE CAMP\"</code>');",
|
||||
"assert(rot13(\"SERR CVMMN!\") === \"FREE PIZZA!\", 'message: <code>rot13(\"SERR CVMMN!\")</code> should decode to <code>\"FREE PIZZA!\"</code>');",
|
||||
"assert(rot13(\"SERR YBIR?\") === \"FREE LOVE?\", 'message: <code>rot13(\"SERR YBIR?\")</code> should decode to <code>\"FREE LOVE?\"</code>');",
|
||||
"assert(rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\") === \"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\", 'message: <code>rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\")</code> should decode to <code>\"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\"</code>');"
|
||||
],
|
||||
"challengeSeed": [
|
||||
"function rot13(codeArr) {",
|
||||
" // Your Code Here",
|
||||
"function rot13(encodedStr) {",
|
||||
" var codeArr = encodedStr.split(\"\"); // String to Array",
|
||||
" var decodedArr = []; // Your Result goes here",
|
||||
" // Only change code below this line",
|
||||
"",
|
||||
" return []; // Change this Line",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line",
|
||||
" return decodedArr.join(\"\"); // Array to String",
|
||||
"}",
|
||||
"",
|
||||
"// Change the inputs below to test",
|
||||
"rot13([ 'S', 'E', 'R', 'R', ' ', 'P', 'B', 'Q', 'R', ' ', 'P', 'N', 'Z', 'C' ]);"
|
||||
"rot13(\"SERR PBQR PNZC\");"
|
||||
],
|
||||
"tail": [
|
||||
""
|
||||
],
|
||||
"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",
|
||||
"}"
|
||||
],
|
||||
"type": "bonfire",
|
||||
"challengeType": "5",
|
||||
|
Reference in New Issue
Block a user