0% found this document useful (0 votes)
3 views

Project 1 - Secret Key Encryption - Solution

The document outlines a mini project focused on secret-key (symmetric-key) encryption, detailing tasks such as frequency analysis for cracking ciphers, encryption using various ciphers and modes, and the effects of padding and error propagation. It compares ECB and CBC modes, highlighting their differences in handling guessable plaintext and data leakage. The project concludes with insights gained about encryption algorithms, modes, and their respective advantages and disadvantages.

Uploaded by

Nayla Greige
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Project 1 - Secret Key Encryption - Solution

The document outlines a mini project focused on secret-key (symmetric-key) encryption, detailing tasks such as frequency analysis for cracking ciphers, encryption using various ciphers and modes, and the effects of padding and error propagation. It compares ECB and CBC modes, highlighting their differences in handling guessable plaintext and data leakage. The project concludes with insights gained about encryption algorithms, modes, and their respective advantages and disadvantages.

Uploaded by

Nayla Greige
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MINI PROJECT 1: SECRET-KEY ENCRYPTION

Objective: The objective of this project is to get familiar with the concepts of the secret-key
(Symmetric-Key) encryption such as encryption algorithms, encryption modes, paddings, and
initial vector.

Task 1: Frequency Analysis:


As we know, Frequency Analysis helps in cracking monoalphabetic substitution ciphers. It counts the
appearance of each character in the ciphertext to determine the frequency of each character.

To apply this, we ran a python program (freq.py) over a given text file (ciphertext.txt) and we got below
results:

After analysing above counts and the ciphertext.txt file, we concluded some common substitutions of the
ciphers directly after seeing the top 20 trigrams and bigrams, such as ‘ytn’ is ‘THE’, ‘v’ is ‘A’ and so, ‘vu’ is
‘AN’, ‘vy’ is ‘AT’ and so on.

Hence, after few hits and trial, we were able to conclude the encryption key and converted it into a
plaintext, as shown below.

Here is the command used to convert ciphertext into plaintext using encryption key:

The Required Plaintext:


Task 2: Encryption using different Ciphers and Modes:
In this task, we have used five different ciphers with different modes to encrypt and decrypt a text file.
Ciphers used are AES-128, Aria-128, BF (Blowfish) and DES.

First, we created a dummy text file (task2_file.txt).

After that, we used AES-128 cipher with CBC mode first, using OPENSSL ENC command line tool, to
encrypt and decrypt the above text file.

AES-128-CBC
The encrypted file looked like below:

And the decrypted file gave our original text back:

We then changed the cipher mode from CBC to CFB:

AES-128-CFB

Encrypted File:

Decrypted File:
After AES, we tried BF (Blowfish) with CBC mode first:

BF-CBC

Encrypted file:

Decrypted file:

DES-CBC

Encrypted file:
Decrypted file:

ARIA-128-CBC

Encrypted file:

Decrypted file:

Task 3: Encryption Mode – ECB vs. CBC:


ECB (Electronic Code Book) and CBC (Cipher Block Chaining) are the two cipher modes with one major
difference. In the CBC mode, we pass an “iv” (an initialization vector which is random and unique) before
encryption just to prevent having the guessable plaintext result in the ciphertext whereas in the ECB
mode, we do not pass any “iv” and therefore, one can see the guessable plaintext result in the ciphertext.

To show the difference, we encrypted a given picture using AES-128 cipher with CBC and ECB mode, as
you can see in the below snapshot:
And since it was a ‘.bmp’ picture, we had to concatenate original picture header with encrypted picture
body.

Below is the combined snapshot:


i.) Original picture (on top left),
ii.) Encrypted picture with AES using ECB (on top right),
iii.) Encrypted picture with AES using CBC (bottom one).

I again tried the same cipher with ECB and CBC mode on a custom image and got the same result, as you
can see the below snapshot:

Commands to encrypt the image with AES cipher using CBC and ECB mode:
Below is the combined snapshot:
i.) Original picture (on top left),
ii.) Encrypted picture with AES using ECB (on top right),
iii.) Encrypted picture with AES using CBC (bottom one).

Our Observations:
i.) ECB mode leaks data about the underlying message being encrypted. The reason this happens
is because it produces identical ciphertext blocks after encrypting identical plaintext blocks.
ii.) CBC mode eliminates the ECB issue. The plaintext of a block is combined with the ciphertext
of the previous block via XOR operation and the result is encrypted.
Task 4: Padding:
We encrypted an 8 byte “test” file using these modes ECB, CBC, CFB, OFB:

ECB and CBC mode add padding to the plaintext because the block size on which encryption will be done
should be 16 bytes (128 bits). If it is shy of this size, then padding is done. CFB and OCB do not need
padding because when you encrypt using Cipher-Feedback (CFB) or Output-Feedback (OFB), then the
ciphertext is of the same size as the plaintext and this is Why padding is not required in these modes.

i.) Creating 3 files of length 5, 10 and 16 bytes, respectively.

ii.) Encrypting f1, f2 and f3 using CBC.

iii.) The size of the encrypted files is 16, 16, and 32 bytes for f1, f2 and f3 respectively, which in
bits is 128 bits, 128 bits and 2 blocks of 128 bits for f3. The size of a block in CBC mode is 128
bits.
iv.) Decrypting the above encrypting files with “-nopad” command.
v.) The paddings which were added during the encryption process in all three files are shown
below:

Task 5: Error Propagation – Corrupted Cipher Text:


How much information can you recover by decrypting the corrupted file, if the encryption mode is ECB,
CBC, CFB, or OFB, respectively?

It depends on several factors such as the encryption mode used, the percentage of corruption in the file,
and many more.

• If a file has been encrypted using ECB mode, each block of data in the file is encrypted
independently of the other blocks. This means that if some blocks of the file are corrupted, it may
still be possible to recover the remaining uncorrupted blocks.
• If a file has been encrypted using CBC mode, each block of data is XORed with the previous block
before encryption, which introduces some randomness into the encryption process. This means
that if some blocks of the file are corrupted, it may still be possible to recover the remaining
uncorrupted blocks, but only if the previous blocks are also uncorrupted. If a corrupted block is
encountered, it will typically cause the decryption process to fail for the remaining blocks.
• If a file has been encrypted using CFB mode, each block of data is encrypted using the previous
block as input to a feedback function, which generates a pseudo-random stream of data. This
stream is then XORed with the plaintext to produce the ciphertext. If some blocks of the file are
corrupted, it may still be possible to recover the remaining uncorrupted blocks, but only if the
feedback function can be reconstructed based on the available information. If a corrupted block is
encountered, it will typically cause the decryption process to fail for the remaining blocks.
• If a file has been encrypted using OFB mode, each block of data is encrypted using a pseudo-
random stream generated from an IV (initialization vector) and a secret key. This stream is then
XORed with the plaintext to produce the ciphertext. If some blocks of the file are corrupted, it
may still be possible to recover the remaining uncorrupted blocks, but only if the IV and secret
key are available, and the feedback function can be reconstructed based on the available
information. If a corrupted block is encountered, it will typically cause the decryption process to
fail for the remaining blocks.

To accomplish Task-5, I created a dummy text file (task5_file.txt) of 1173 bytes and encrypted it with AES-
128 cipher with CBC, CFB, ECB and OFB modes, as you can see in the below snapshots:

Dummy text file properties:


Commands to encrypt the above text file with AES cipher using different modes:

Now, I have corrupted the 55th byte of all the ciphertext files using the hex editor. After that, I decrypted
all the different corrupted ciphertexts one by one, shown in the below snapshots:

ECB:

Result:
Observation:

Surprisingly, we found our assumption partial true as it was able to recover few portion of the plaintext
but there were many uncorrupted blocks and since it works independently, it should have recovered
more portion of the plaintext as per our assumption.

CBC:

Result:

Observation:

We found our assumption true as it was able to recover some portion of the plaintext but not all as it
works sequentially and depends on the previous ciphertext block. So, once it encountered the corrupted
ciphertext, the decryption process failed.

CFB:

Result:
Observation:

We found our assumption true as it is similar to CBC mode and it was able to recover a portion of the
plaintext until it encountered the corrupted ciphertexts.

OFB:

Result:

Observation:

We found our assumption true as it was able to recover some portion of the plaintext and since this mode
is similar to CFB, it didn’t able to recover the remaining portion of plaintext after it encountered
corrupted ciphertext.

Conclusion:
After successfully doing each task, I learned how to use different secret key encryptions, their algorithms,
used different ciphers to encrypt and decrypt texts and pictures, paddings, and error propagation. I also
learned about pros and cons of different modes.

You might also like