roofline.devPublic Beta

Matrix Decrypt-Encrypt

0MEDIUMRankedReport issue

A Hill cipher is a cipher based on matrix multiplication. To encrypt a message c\underline{c} of length 1n4096\leq 1 n \leq 4096 in an alphabet of size 1l655351 \leq l \leq 65535, pick some key AA of size n×nn \times n and compute cA=Acmodl\underline{c}_A = A\underline{c} \mod l. To decrypt the message, apply A1cA=(A1A)c=Ic=cA^{-1}\underline{c}_A = (A^{-1}A)\underline{c} = I\underline{c} = \underline{c}.

For this problem, given a message cA\underline{c}_A (encrypted for AA), the encryption key AA, and the encryption key BB, rekey the message cA\underline{c}_A to become cB\underline{c}_B.

The input cAc_A will be supplied in c. The final output cBc_B must also be placed in c.

Input

  • A - original encryption key.
  • B - target encryption key.
  • n - size of the Hill cipher key matrices.
  • l - alphabet modulus.
  • c - ciphertext encrypted under A, provided in place.

Output

  • c - the input vector modified in place to become cB\underline{c}_B.
Open on a desktop browser to write and submit code.