Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been wondering what approach to take in order to figure out what key was used to encrypt a message using the hill cipher. I know it is possible to obtain it even if it were just a known-plaintext attack, so it should be fairly possible for a chosen-plaintext one. I'm trying to figure it out with just intuition, but since I know freq. analysis won't be of help, I don't know what else to try. I want to get my head around this, but could someone point me in the right direction?

share|improve this question
up vote 3 down vote accepted

Sure. Assuming that you're using the encoding $A = 0$, $B = 1$, etc., just choose your plaintext messages to be the one-block strings:

$$ BA \dots A \\ AB \dots A \\ \vdots \\ AA \dots B $$

The encryptions of these strings will then directly give you the columns of your key matrix.

share|improve this answer
Sorry, it seems like I misunderstood your answer. I thought I could just encrypt each letter in the plaintext at a time, but it doesn't work since the key matrix is at least 2x2, right? Could you elaborate a bit more on what you mean by one-block strings? – Emyr Sep 27 '12 at 2:04
@Emyr: See this description of the Hill cipher: for an n.n matrix, plaintext letters are grouped by vectors of n letters. Ilmari Karonen suggest to encipher the n distinct vectors of n letters with n-1 A and 1 B; the resulting ciphertext is n vectors of n letters, which form the n.n key matrix. – fgrieu Sep 27 '12 at 9:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.