[go: up one dir, main page]

0% found this document useful (0 votes)
115 views11 pages

Lab Assignment Subject: Cryptography

This document summarizes a student's lab assignment on cryptography. The assignment consisted of 7 tasks: 1) generating encryption keys with and without random seeding; 2) guessing an encryption key; 3) measuring entropy on a system; 4) obtaining random numbers from /dev/random; 5) obtaining pseudo-random numbers from /dev/urandom; 6) cryptanalyzing a shift cipher; and 7) cryptanalyzing a single-column transposition cipher. For each task, the student provided screenshots and explanations of their process and results.

Uploaded by

riya
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)
115 views11 pages

Lab Assignment Subject: Cryptography

This document summarizes a student's lab assignment on cryptography. The assignment consisted of 7 tasks: 1) generating encryption keys with and without random seeding; 2) guessing an encryption key; 3) measuring entropy on a system; 4) obtaining random numbers from /dev/random; 5) obtaining pseudo-random numbers from /dev/urandom; 6) cryptanalyzing a shift cipher; and 7) cryptanalyzing a single-column transposition cipher. For each task, the student provided screenshots and explanations of their process and results.

Uploaded by

riya
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/ 11

LAB ASSIGNMENT

Subject : Cryptography

TASK 1: Generating Encryption Key in a Wrong Way


First I compiled the program and run it and took a screenshot as shown in the figure
1.1. Then I removed the srand(time(NULL), recompiled the program and run it and took a
screenshot as shown in the figure 1.2. hence it can be observed that with srand() function , the
output of the program generates different number. But without srand() function the output of
this program are same. Hence the time(NULL) creates the seed for srand() and srand()

function is used to initial the random number generator.

Figure 1.1
Figure 1.2

TASK 2: Guessing the Key


We know that we have a plain text , ciphertext ,IV, functions of generating key and the range
of random number seed from the given question. So first I compiled and run the program to
generate the range of random number seed using the commands -d “2018-4-17 21:08:49”
+%s and data -d “2018-4-17 23:08:49” +%s as shown in figure 2.1. Then I used this range in
the task1 program to create the keys written to keys.txt as in figure 2.2. After I create all the
possible keys, I used the decrypt.py program to obtain the right key shown in the figure 2.3.

Figure 2.1
Figure 2.2

Figure 2.3
TASK 3: Measure the Entropy of Kernel
After I run the watch -n .1 cat /proc/sys/kernel/random/entropy_avail and monitor it ,
I test the command by randomly moving and not moving the mouse and other keys. If I don’t
move the mouse the entropy increases very slowly. But if I move the mouse slowly or press
any key in the keyboard the entropy changes fast. The screenshot figure 3.2, shows the
entropy when I move the mouse and press a key and the figure 3.1 does not move the mouse.
Thus in my observation, reading large files increases the entropy significantly.

Figure 3.1

Figure 3.2
Task 4: Get Sudo Random Numbers from /dev/random
After running the cat /dev/random | hexdump command and monitoring it , tested this
command by randomly moving and not moving the mouse, is shown in screenshot figure 4.1
and 4.2. If I don’t move the mouse the entropy increases very slowly and get the random
numbers very slowly. But if I move the mouse the entropy changes fast and gets the random
nymber more fast. This is the /dev/random device is a blocking device, when the entropy
reaches zero, /dev/random will block until it gains enough randomness. Because /dev/random
will block on some systems if there is not enough entropy available. I can quickly draw
entropy from the system by creating lots of session ids, then it can lead the system block
when creating another session id. Then the system can not respond for some time.

Figure 4.1
Figure 4.2

TASK 5: Get Pseudo Random Numbers from /dev/urandom


After I run cat /dev/urandom | hexdump, in fig 5.1 creates a lot random numbers in a
fast speed. Then I measure the quality of the random numbers by using ent, and results are
shown in fig 5.2 and fig 5.3. From the Chi square distribution and correlation coefficient I
can know random numbers in fig 5.3 are better than numbers in fig 5.2.

Figure 5.1
Figure 5.2

Figure 5.3

Now the code in task1.c is modified for writing a new 128 bit key using /dev/urandom. As
shown in fig 5.4, because of using /dev/urandom, I can get a lot of random numbers.
Figure 5.4

TASK 6:Cryptanalysis of Shift Cipher


After compiling the program and running it the screenshots are shown in the figure
6.1 ,figure 6.2 and figure 6.3.In a shift cipher , since the shift must be the number between 0
and 25, each and every possibility is tried to match the string

Figure 6.1
Figure 6.2

Figure 6.3

Task 7:Cryptanalysis of Single Columnar Transposition


The code for singular columnar transposition and the output screenshot is shown
below,

import math

key = "HACK"

def encryptMessage(msg):
cipher = ""

k_indx = 0

msg_len = float(len(msg))

msg_lst = list(msg)

key_lst = sorted(list(key))

col = len(key)

row = int(math.ceil(msg_len / col))

fill_null = int((row * col) - msg_len)

msg_lst.extend('_' * fill_null)

matrix = [msg_lst[i: i + col]

for i in range(0, len(msg_lst), col)]

for _ in range(col):

curr_idx = key.index(key_lst[k_indx])

cipher += ''.join([row[curr_idx]

for row in matrix])

k_indx += 1

return cipher

def decryptMessage(cipher):

msg = ""

k_indx = 0

msg_indx = 0

msg_len = float(len(cipher))

msg_lst = list(cipher)

col = len(key)

row = int(math.ceil(msg_len / col))

key_lst = sorted(list(key))

dec_cipher = []

for _ in range(row):

dec_cipher += [[None] * col]

for _ in range(col):

curr_idx = key.index(key_lst[k_indx])

for j in range(row):
dec_cipher[j][curr_idx] = msg_lst[msg_indx]

msg_indx += 1

k_indx += 1

try:

msg = ''.join(sum(dec_cipher, []))

except TypeError:

raise TypeError("This program cannot", "handle repeating words.")

null_count = msg.count('_')

if null_count > 0:

return msg[: -null_count]

return msg

msg = "Hello World"

cipher = encryptMessage(msg)

print("Encrypted Message: {}".format(cipher))

print("Decryped Message: {}".format(decryptMessage(cipher)))

Figure 7.1

You might also like