The permutation ciphers are used to generate a ciphertext (encrypted text) by re-arranging the position of the letters in a given plaintext.

How it works?

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:

  • Encrypt a plain text with a given permutation.
  • Decrypt an encrypted ciphertext with a given permutation.
  • Decrypt an encrypted ciphertext with an unknown permutation.

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 .......
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.