The permutation ciphers are used to generate a ciphertext (encrypted text) by re-arranging the position of the letters in a given plaintext.
1. Divide a given plaintext into blocks of n letters, and use x as padding if necessary. n = 4; {ther eare soma nyci pher sxxx}
2. Apply a permutation to each block.
permutation = (2,4,1,3); {hrte acer oasm yinc hrpe xxsx}
1234 1234 1234 1234 1234 1234
ther eare soma nyci pher sxxx
2413 2413 2413 2413 2413 2413
hrte acer oasm yinc hrpe xxsx
The program needs to get the following information from the user:
Here's what a sample run should look like, with the keyboard inputs in italics
> ./PermCipher
Usage: ./PermCipher-i InputFileName -o OutputFileName
Options: -e Encrypt
-d Decrypt
-c Crack with Brute-Force
> ./PermCipher -e -i PlaintextFile -o CiphertextFile
Welcome to the Permutation Cipher
Mode: Encrypt
Input File: PlaintextFile
Output File: CiphertextFile
Please enter the block size (2-4) and the permutation (e.g., 4 2413): 4 2413
Encrypted ciphertext file: 4 2413 hrteaceroasmyinchrpexxsx
> ./PermCipher -d -i CiphertextFile -o PlaintextFile
Welcome to the Permutation Cipher
Mode: Decrypt
Input File: CiphertextFile
Output File: PlaintextFile
The block size and the permutation are detected: 4 2413
Decrypted ciphertext file: therearesomanyciphers
> ./PermCipher -c -i CiphertextFile -o PlaintextFile
Welcome to the Permutation Cipher
Mode: Brute-force crack
Input File: CiphertextFile
Output File: PlaintextFile
Possible decrypted ciphertext .......