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

The purpose of this question is to ask students to decrypt a message encrypted with a Hill cipher.

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

You received the message {ciphertext}, encrypted by a Hill cipher using the 2x2 matrix $\\var{M}$.

", "advice": "

We start by convert each letter in the encrypted message to the number corresponding to its place in the alphabet: {codenumbers}

\n

Since the matrix that was used to encrypt the message is a 2x2 matrix, we arrange these letters in two columns: $\\var{pc}$. Then to decrypt we just need to multiply by the inverse of $\\var{M}\\pmod{26}$. We can calculate that $\\var{M}^{-1} = \\var{M1}\\pmod{26}$.

\n

Then multiplying we find that the original message (in numeric form) is $\\var{decryptedText}$. Replacing each number by the letter it represents, and arranging them in a row gives \"{plaintext}\".

", "rulesets": {}, "extensions": ["numbertheory"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"ciphertext": {"name": "ciphertext", "group": "Ungrouped variables", "definition": "join(map(upper(letterordinal(mod(x,26))),x,flatten(p*M)),\"\")", "description": "", "templateType": "anything", "can_override": false}, "plaintext": {"name": "plaintext", "group": "Ungrouped variables", "definition": "random([\"SOLVED\",\"WISDOM\",\"SIMPLE\",\"FRIEND\",\"STRONG\",\"CIPHER\"])", "description": "", "templateType": "anything", "can_override": false}, "plainletters": {"name": "plainletters", "group": "Ungrouped variables", "definition": "map(plaintext[i],i,0..len(plaintext)-1)", "description": "", "templateType": "anything", "can_override": false}, "plainnumbers": {"name": "plainnumbers", "group": "Ungrouped variables", "definition": "map(filter(letterordinal(x)=lower(l),x,0..25)[0],l,plainletters)", "description": "", "templateType": "anything", "can_override": false}, "p": {"name": "p", "group": "Ungrouped variables", "definition": "matrix(map([plainnumbers[2*i],plainnumbers[2*i+1]],i,0..len(plainnumbers)/2-1))", "description": "", "templateType": "anything", "can_override": false}, "M": {"name": "M", "group": "Ungrouped variables", "definition": "matrix([[random(1..26),random(1..26)],[random(1..26),random(1..26)]])", "description": "

Hill cipher encryption matrix

", "templateType": "anything", "can_override": false}, "d": {"name": "d", "group": "Ungrouped variables", "definition": "mod(det(M),26)", "description": "", "templateType": "anything", "can_override": false}, "M1": {"name": "M1", "group": "Ungrouped variables", "definition": "map(mod(x,26),x,matrix([[M[1][1],-M[0][1]],[-M[1][0],M[0][0]]])*dinv)", "description": "", "templateType": "anything", "can_override": false}, "g": {"name": "g", "group": "Ungrouped variables", "definition": "gcd(d,26)=1", "description": "", "templateType": "anything", "can_override": false}, "dinv": {"name": "dinv", "group": "Ungrouped variables", "definition": "invert(d,26)", "description": "", "templateType": "anything", "can_override": false}, "codenumbers": {"name": "codenumbers", "group": "Ungrouped variables", "definition": "map(filter(letterordinal(x)=lower(l),x,0..25)[0],l,map(ciphertext[i],i,0..len(ciphertext)-1))", "description": "", "templateType": "anything", "can_override": false}, "pc": {"name": "pc", "group": "Ungrouped variables", "definition": "matrix(map([codenumbers[2*i],codenumbers[2*i+1]],i,0..len(codenumbers)/2-1))", "description": "", "templateType": "anything", "can_override": false}, "decryptedText": {"name": "decryptedText", "group": "Ungrouped variables", "definition": "map(mod(x,26),x,pc*M1)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "g", "maxRuns": 100}, "ungrouped_variables": ["ciphertext", "plaintext", "plainletters", "plainnumbers", "p", "M", "d", "dinv", "M1", "g", "codenumbers", "pc", "decryptedText"], "variable_groups": [], "functions": {}, "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 the message (in capital letters)?

", "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/"}]}]}], "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}]}