Monoalphabhatic Random Subsitution Cipher is pretty hard to crack compared to Ceasar Cipher especially through brute force but using frequency analysis, provided enough cipher text is easy.
But what if key for the subsitution changes lets say every 16 characters. Then there wouldn't be enough cipher text for frequency analysis. So what should be done to crack such cipher?
Steps of encryption
- All characters of string are lowercased.
- Password is interpreted:
- First 3 characters of password are taken as radix 64 number (number in base 64) so it creates a number which is used as seed in a PRNG.
- Last 3 characters are interpreted in the same way to produce another number which is used as multiplier in PRNG. This multiplier is incremented by 1 every 16 characters of plain text are encrypted.
- Middle most characters are also converted to a number used to increment seed after every 16 characters of plain text are encrypted.
- Main Encryption starts by suffling a array that contains 26 characters of English using Fisher Yates Suffle algorithm.
- Fisher Yates uses a modified version of Linear Congruent Generator in which
xn = xn * multiplier + n (mod 2^32)
where n is index of seed. Because of changing increment, it makes it hard to determine previous seed.
- To substitute individual characters, first alphabet is located on unshuffled array so A = 0, B = 1 and so on...
Then they are subsituted by character on that index in shuffled array. For example, in shuffled array, T is located at 0, so in plain text every A will be subsituted with T.
- Any other characters like space, full stop, etc. are ignored.
- Go back to step 3 untill all text is encrypted.
Note that, though it encrypts text in blocks for 16 characters, it does not add any padding in text. Cipher text is always same to plain text in length.
Also what would happen if instead of encrypting 26 characters of English, I encrypt all 256 characters of a single byte?
I hope I have explained question as clearly as possible.