// Numbas version: exam_results_page_options {"name": "Affine Cipher Decryption", "extensions": ["numbertheory"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Affine Cipher Decryption", "tags": [], "metadata": {"description": "

This question gives a text encrypted with an affine cipher and asks students to decrypt it.

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

Guillermo wants to help his SIT281 students by giving them the answer to a question. But he doesn't want to share that too openly. He uses the affine cipher $\\var{a}x+\\var{b}\\pmod{26}$ to encrypt the text and sends the secret message {secrettext}.

", "advice": "

The first step is to convert the secret \"{secrettext}\" to numbers, according to their place in the alphabet. This gives us {secretcode}. Each character is then decrypted separately.

\n

The encryption used is $s =\\var{a}x+\\var{b}\\pmod{26}$, where $x$ is the plain text character value to encode, and $s$ is the corresponding secret. So, to decrypt we need to invert this function. This gives us: $x=\\var{a}^{-1}\\cdot(s-\\var{b})\\pmod{26}$. The inverse of $\\var{a}$ is $\\var{inva}$. So we apply the function $\\var{inva}\\cdot(s-\\var{b})\\pmod{26}$ to each number in {secretcode}. This gives us the list {decryptedcode}.

\n

From there, we just replace these numbers by the corresponding letter, to get the string \"{decryptedtext}\".

", "rulesets": {}, "extensions": ["numbertheory"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"plaintext": {"name": "plaintext", "group": "Ungrouped variables", "definition": "random([\"HOWAREYOU\",\"BEAUTIFUL\",\"KNOWLEDGE\",\"FRIENDSHIP\",\"EDUCATION\",\"EXCELLENT\",\"IMPORTANT\"])", "description": "", "templateType": "anything", "can_override": false}, "a": {"name": "a", "group": "Ungrouped variables", "definition": "random(filter(coprime(x,26),x,2..25))", "description": "", "templateType": "anything", "can_override": false}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random(1 .. 25#1)", "description": "", "templateType": "randrange", "can_override": false}, "plaincode": {"name": "plaincode", "group": "Ungrouped variables", "definition": "toint(plaintext)", "description": "", "templateType": "anything", "can_override": false}, "secretcode": {"name": "secretcode", "group": "Ungrouped variables", "definition": "map(mod(a*x+b,26),x,plaincode)", "description": "", "templateType": "anything", "can_override": false}, "secrettext": {"name": "secrettext", "group": "Ungrouped variables", "definition": "join(map(upper(letterordinal(s)),s,secretcode),\"\")", "description": "", "templateType": "anything", "can_override": false}, "inva": {"name": "inva", "group": "Ungrouped variables", "definition": "invert(a,26)", "description": "", "templateType": "anything", "can_override": false}, "decryptedcode": {"name": "decryptedcode", "group": "Ungrouped variables", "definition": "map(mod(inva*(s-b),26),s,secretcode)", "description": "", "templateType": "anything", "can_override": false}, "decryptedtext": {"name": "decryptedtext", "group": "Ungrouped variables", "definition": "join(map(upper(letterordinal(s)),s,decryptedcode),\"\")", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["plaintext", "a", "b", "plaincode", "secretcode", "secrettext", "inva", "decryptedcode", "decryptedtext"], "variable_groups": [], "functions": {"toint": {"parameters": [["word", "string"]], "type": "list", "language": "javascript", "definition": "var s = []\nfor (var c of word) {\n s.push(c.charCodeAt(0)-65)\n}\nreturn s"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "patternmatch", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

What was Guillermo's original message?

", "answer": "{plaintext}", "displayAnswer": "", "matchMode": "exact"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}, {"name": "Guillermo Pineda", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/20075/"}]}]}], "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}, {"name": "Guillermo Pineda", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/20075/"}]}