Lab Assignment Subject: Cryptography
Lab Assignment Subject: Cryptography
Subject : Cryptography
Figure 1.1
Figure 1.2
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
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
Figure 6.1
Figure 6.2
Figure 6.3
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)
msg_lst.extend('_' * fill_null)
for _ in range(col):
curr_idx = key.index(key_lst[k_indx])
cipher += ''.join([row[curr_idx]
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)
key_lst = sorted(list(key))
dec_cipher = []
for _ in range(row):
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:
except TypeError:
null_count = msg.count('_')
if null_count > 0:
return msg
cipher = encryptMessage(msg)
Figure 7.1