Aishdec is a NodeJS console script that'll try to decrypt a Vigenere ciphred text using Kasiski's method.
This works with the Kasiski's method principles:
- There're common text paths in the text with a length of 2-3-4... (Relative)
- The distance between these common paths is a multiple of the key length
To put this in practice, we search in the text for common trigrams, and then we calculate the distance between these. Then, with these distances, we get the greates common divisor, that'll be the length of the key we're looking for. After that, we find out N substrings derived from the original text, with N equals to the key length. Example: ABCDEF with key length equals 3. We'll get 3 substrings:
- AD (A, A + 3...)
- BE (B, B + 3...)
- CF (C, C + 3...)
With the substrings found, now you're gonna look for the most frequent letters on each substring. In our script, we're using for the most common letter in English alphabet, that's the E letter (We also used A, but we didn't found the expected resultes). Then, with the common letter found on EACH substring, we know that E has a distance of 4 letters with the A, so we'll look for the relative A letter to our relative E found. Example: If we found these frequent letters: [G, K, L] the relative As should be: [E, G, H]
And finally, these As letter should be the key that' we're looking for, and we can decrypt the message with simple specials math.
You're gonna need Node
Then you're gonna need to install the project dependencies
npm install
You can run the next command to try the automatic decryption in the package's dir
node aishdec
You can also personalize a bit the script execution, defining some stuff like the size of substrings to search in the text, or the length of the key (In case you know it)
node aishdec --group-by=NUMBER (Default one is 3)
node aishdec --key-length=NUMBER
node aishdec --key=TEXT (This will just decrypt the whole message without JSON details)
Also, you can import aishdec and use it in your code as a simple function