# Crack a polyalphabetic cipher given a pair of (plaintext, ciphertext) encrypted by it

The original question only states that a classical cipher is used, and I am going to articulate 1) why I think a polyalphabetic substitution cipher is used AND 2) my attempts so far.

## The Question

c1 = rhlxhei rb niu ir-wbbxug "qeejv," rgj mbfo sdg
m1 = friends by the so-called "posts," but they can
c2 = fypx pd jkx teoyde nupyd wbd hhtfmo yqvlfqeu
m2 = ?


## Which type of cipher is used

1. If it is a transposition cipher, then for each character, the number of its occurrences should be identical in both plaintext and ciphertext. (Contradiction)
2. It is a monoalpbetic substitution cipher, the same character in plaintext should be mapped to the same character in ciphertext. (Contradiction)

As a result, it should be a polyahplabetic substitution cipher.

## My Attempts

### IC (Index of Coincidence)

I googled that Index of Coincidence can be used to guess the key length, but that is based on that the length of the ciphertext is statistically long enough.

### Calculate Offsets

I then realized that if Vigenère cipher is used, then for each character of m1 and c1, I can calculate the offset between them, and figure out the repeating pattern in the offsets.

To make it clear, offsets[i] = (c[i] + 26 - m[i]) % 26, and offsets is printed below

12 16 3 19 20 1 16 16 3 20 1 16 16 3 20 1 16 12 16 3 1 16 12 16 3 16 12 16 19 20 1 16 16 3 19

However, there are two difficulties.

1. Although there are some repeating numbers (e.g. 16, 19, 1, etc.), I failed to extract the exact pattern from the offsets.
2. If I directly applied those offsets (reversely) to c2, the result does not make sense (m2 = rosq qt mey jhiztq qvfkt mnt bijvph otofggux'), so I am wondering maybe the plaintext is incorporated into the key in some way.

Please correct me if the process described above is somewhat wrong and direct me if there is a certain way to take advantage of the known (c1, m1) pair. Thank you!

I love playing with ciphers where the word boundaries are given!

Looking at $$c_1$$ and $$m_1$$, the shift distance from the plaintext character to the cipher text character only takes on the values of: $$\big[ 1, 6, 7, 10, 14, 23, 25 \big]$$.

If the character positions are labeled $$0, \dots, 34$$ in m1/c1, every position where ($$i \mod 5 =0$$) has a shift of $$1$$, except for positions $$0$$ and $$25$$.

idx=>            1             2             3
0123456 78 901 23 456789  01234   567 8901 234
c1 = rhlxhei rb niu ir-wbbxug "qeejv," rgj mbfo sdg
?    |      |      |      |       ?     |
m1 = friends by the so-called "posts," but they can
c2 = fypx pd jkx teoyde nupyd wbd hhtfmo yqvlfqeu
m2 =      o      s      m      a             e


Using these two assumptions and a list of the $$10000$$ most common English words yields a small number of possibilities for each word.

['give' 'live' 'time']
['on' 'or']
['guy' 'ill' 'the' 'try']
['social']
['media']
['can' 'car' 'tan' 'van']
['really']
['increase']


Picking the words that seem to make sense yields: "time on the social media can really increase".

When investigating a Vigenère type cipher with some unencrypted characters (such as spaces and punctuation), the obvious question to ask is whether those unencrypted characters still advance the keyword position or not.

You seem to have assumed that they do not. In this case, the opposite assumption may be more fruitful. (In general, of course, the only real way to know is to try both ways and see which one works better.)

The keyword obtained in this manner does not seem to match a real word in any language I know, not even after accounting for variations like A=0 vs. A=1 or use of subtraction vs. addition. But it does decrypt the plaintext.