Search code examples
encryptioncryptographyvigenere

Make 1 key from 2 vigenere keys


I have this school assignment about Vigenere code.

I've got 2 keys: AB and XYZ. A text is encrypted twice with these keys. The questions are:

  • How to make 1 key out of those 2?
  • How to make 1 key when there are 3 keys?

Solution

    1. Choose the length of the combined key as the least common multiple of the key lengths.
    2. Repeat each key until it fills the combined key
    3. Add all the repeated keys.

    For example with AB and XYZ assuming A=0:

    1. The lengths are 2 and 3, the common multiple is 6.
    2. AB AB AB and XYZ XYZ
    3. A+X, B+Y, A+Z, B+X, A+Y, B+Z = XZZYYA

    This algorithm works with any number of keys.