All problems
Hill Cipher 2x2 Encrypt
Problem
Encrypt uppercase text with a 2x2 Hill cipher. Process the text in pairs; for each pair [x0, x1], the ciphertext pair is
c0 = (k00 * x0 + k01 * x1) mod 26 c1 = (k10 * x0 + k11 * x1) mod 26
Return the uppercase ciphertext. Assume the text length is even.
Hint
All matrix products are taken modulo 26, letter by letter.
Test cases
case 1
in: ["HELP",[[3,3],[2,5]]]
expected: "HIAT"
case 2
in: ["ABCD",[[1,2],[3,4]]]
expected: "CEIS"
case 3
in: ["SECRET",[[2,3],[1,5]]]
expected: "WMDJNV"
case 4
in: ["ZZZZ",[[3,3],[2,5]]]
expected: "UTUT"
Starter codePython
def hill_encrypt2(text, key):
# Your code here
pass4 test cases · run your code against them in the editor