// Numbas version: finer_feedback_settings {"name": "Substitution cipher encryption/decryption", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Substitution cipher encryption/decryption", "tags": [], "metadata": {"description": "

A straightforward test of encrypting and decrypting an eight-letter message with the Substitution Cipher.  Message letters are generated uniformly at random from the English alphabet and the key is a uniformly chosen random permutation of the alphabet.  Students are expected to be able to map English letters onto elements of $\\mathbb{Z}_{26}$ in the usual order.

", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "

Suppose we wish to encrypt the (nonsense) plaintext {message} using the Substitution Cipher.

", "advice": "

a) We look up each message letter in turn in the top row of the key, and replace it by the corresponding letter in the bottom row.  So {message[0]} is replaced by {alphabet[numberkey[numbermessage[0]]]}, which then becomes {numberkey[numbermessage[0]]}, and so on.

\n

b) This time we look up each ciphertext letter in the bottom row of the key, and replace it by the corresponding letter in the top row.  So {ciphertext[0]} is replaced by {alphabet[map(indices(numberkey,numberciphertext[i])[0],i,0..7)[0]]}, which then becomes {map(indices(numberkey,numberciphertext[i])[0],i,0..7)[0]}, and so on.

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"alphabet": {"name": "alphabet", "group": "Ungrouped variables", "definition": "\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"", "description": "", "templateType": "anything", "can_override": false}, "numbermessage": {"name": "numbermessage", "group": "Ungrouped variables", "definition": "Repeat(Random(0..25),8)", "description": "", "templateType": "anything", "can_override": false}, "message": {"name": "message", "group": "Ungrouped variables", "definition": "join(map(alphabet[x],x,numbermessage),\"\")", "description": "", "templateType": "anything", "can_override": false}, "numberkey": {"name": "numberkey", "group": "Ungrouped variables", "definition": "deal(26)", "description": "", "templateType": "anything", "can_override": false}, "key": {"name": "key", "group": "Ungrouped variables", "definition": "join(map(alphabet[x],x,numberkey),\"\")", "description": "", "templateType": "anything", "can_override": false}, "displaykey": {"name": "displaykey", "group": "Ungrouped variables", "definition": "latex(join([join([safe(\"\\\\begin{array}{cccccccccccccccccccccccccc}\"),join([join(map(alphabet[i],i,0..25),\"&\"),join(map(key[i],i,0..25),\"&\")],\"\\\\\\\\\")],\"\"),safe(\"\\\\end{array}\")],\"\"))", "description": "", "templateType": "anything", "can_override": false}, "numberciphertext": {"name": "numberciphertext", "group": "Ungrouped variables", "definition": "Repeat(Random(0..25),8)", "description": "", "templateType": "anything", "can_override": false}, "ciphertext": {"name": "ciphertext", "group": "Ungrouped variables", "definition": "join(map(alphabet[x],x,numberciphertext),\"\")", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["alphabet", "numbermessage", "message", "numberkey", "key", "displaykey", "numberciphertext", "ciphertext"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "matrix", "useCustomName": false, "customName": "", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Encrypt the plaintext using the key $\\var{displaykey}$.  (Express your answer as a sequence of elements of $\\mathbb{Z}_{26}$.)

", "correctAnswer": "matrix(map(numberkey[numbermessage[i]],i,0..7))", "correctAnswerFractions": false, "numRows": 1, "numColumns": "8", "allowResize": false, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": 0, "minRows": 1, "maxRows": 0, "prefilledCells": ""}, {"type": "matrix", "useCustomName": false, "customName": "", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Decrypt the ciphertext {ciphertext} using the key {displaykey}. (Express your answer as a sequence of elements of $\\mathbb{Z}_{26}$.)

", "correctAnswer": "matrix(map(indices(numberkey,numberciphertext[i])[0],i,0..7))", "correctAnswerFractions": false, "numRows": 1, "numColumns": "8", "allowResize": false, "tolerance": 0, "markPerCell": true, "allowFractions": false, "minColumns": 1, "maxColumns": 0, "minRows": 1, "maxRows": 0, "prefilledCells": ""}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Maura Paterson", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7001/"}], "resources": []}]}], "contributors": [{"name": "Maura Paterson", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7001/"}]}