1. Implement the Playfair cipher, in C, C++ or Java. The name of your program should be
Playfair.c or Playfair.cpp or Playfair.java. Include in your report instructions on how to
compile your code.
The command syntax should be as follows:
playfair -e key <plaintext.txt> <ciphertext.txt>
playfair -d key <ciphertext.txt> <plaintext.txt>
where the -e option is associated with encryption and the -d option is associated with decryption.
You may assume all input is lower case without punctuation.
You should use the same convention described below regarding the encryption of diagonally related plaintext pair elements:
A pair of plaintext X1X2 is encrypted to Y1Y2
according to the following rules:
– X1X2 in the same row: Y1 and Y2 are the two
characters to the right of X1 and X2 (cyclic).
– X1X2 in the same column: Y1 and Y2 are the two
characters below X1 and X2 (cyclic).
– X1= X2 : A separating character (anything, X, Z
…) is inserted in the plaintext between the two.
This is really a pre-encryption phase.
– X1X2 different rows & columns: Y1 and Y2 are the
other two corners of the rectangle with X1 and X2
as corners. The direction we shall take for the
example is anticlockwise from the first element to
the second but this is arbitrary although we must
Several things to note:
- Your program must be able to cope with special inputs, such as replacing 'i' with 'j' (or vice
versa) during the encryption/decryption
- When inserting additional characters during the encryption, you will need to remove them
during the decryption.
- To make your program more robust, you may add important information, such as the length
of the ciphertext. However, this should ensure that you will get the decryption process done
- Be careful with the following sample input `zzzz'.
You also need to:
- First, generate a random keyfile keyfile.txt.
- Generate the ciphertext file Ctext-3.txt obtained by encrypting Ptext-1.txt under the key
- In your report, describe the statistical properties of Ctext-3 and discuss how they compare
with those of Ctext-1 and Ctext-2, remembering that Ctext-1 and Ctext-3 are associated
with the same plaintext. Include a comparative graph of the letter frequency distributions.
Write your report in a file called Report2.pdf.
- Discuss a way to decrypt the Playfair cipher without using the key. Show your argument by
decrypting the ciphertext Ctext-3 assuming that you don't know the key. The discussion will
need to be written in the same file Report2.pdf.
- To test the correctness of your program, one can just simply test with
playfair -d keyfile.txt Ctext-3.txt Output.txt
where the keyfille.txt is in fact empty, and your program should do an automatic decryption
and verify whether the file Output.txt is identical with Ptext-1.txt by executing
diff Output.txt Ptext-1.txt
2. Implement the S1 box from DES algorithm in Java or C++. Your program should accept one parameter, namely the input of S1 box in decimal. Then, your program must display:
_ The converted input in binary;
_ The output of S-box 1 in binary; and
_ The output of S-box 1 in decimal.
See the example below:
$ S-box1 46
The input of S-box1 in binary: 1 0 1 1 1 0
The output of S-box1 in binary: 1 0 1 1
The output of S-box1 in decimal: 11
In the above example, 46 is the input to the S-box 1.
Get Free Quote!
424 Experts Online