# Part 1: X9.31 Pseudo-Random Number Generator

Section 10.6 of Lecture 10 talks about the ANSI X9.31 cryptographically secure PRNGs. Your task is to implement a more modern version of this PRNG with the following requirements:

1. Instead of using 3DES for encrypting the 64-bit vectors as indicated in the lecture notes, use your implementation of AES from homework 4 to encrypt 128-bit vectors. By the way, AES is used instead of 3DES in the newer implementations of X9.31.

2. Use the following as your 128-bit seed value: V0 = computersecurity

3. Use the following as your AES key: anexaminedlif eistrulyworthliving

4. Your script should define the PRNG function in the following manner:

#v0: 128-bit BitVector object containing the seed value

#dt: 128-bit BitVector object containing the date and time

#key_file: .txt file containing the encryption key in ASCII for AES

#totalNum: integer indicating the total number of random numbers to generate

#returns a list of size totalNum containing the random numbers def x931(v0, dt, key_file=’key.txt’, totalNum):

5. To create a 64-bit BitVector containing the date and time, you can use the number returned by the time() function in the built-in Python time library (technically this number denotes the number of seconds from an epoch reference date as specified by your operating system). You can multiply this value by one million to get a whole number, which can be cast as an integer (different systems may give more precision, but for the sake of consistency, multiply by one million regardless). To get a 128-bit vector this way, generate two 64-bit vectors consecutively and concatenate the first vector as the left half and the second vector as the right half. In a normal ANSI X9.31 implementation, you would get the current date and time for every random number generated. For simplicity’s sake in this homework, you can use the same dt vector for each random number generated.

# Part 2: AES Encryption in Counter Mode

In Homework 2, the sudden changes in the image of the helicopter allowed you to see the helicopter’s outline even after encrypting the image. To prevent this from happening, implement AES in CTR mode as described in section 9.5.5 of the lecture notes. Use your implementation of AES from homework 4 as a starting point. Use a random number generated from your X9.31 implementation in Part 1 of this homework for the CTR mode initialization vector.

• Use the following as your AES key: applesbananaspeachesstrawberries

• The encryption function should have the following format:

#iv: 64-bit initialization vector generated from X9.31

#image_file: input .ppm image file name

#out_file: encrypted .ppm image file name

#key_file: .txt file containing encryption key in ASCII

#Encrypts image_file using CTR mode AES and writes said file to out_file def ctr_aes_image(iv,image_file=’image.ppm’,out_file=’enc_image.ppm’,

key_file=’key.txt’):

• To ensure that the encryption does not take too long, write each block to the output image file as you encrypt it. Do not store the entire encrypted image in a BitVector as you encrypt it (this will cause a slowdown due to the size of the image).

• As in homework 2, the encrypted image should still be a viewable image file and as such should have an image header (though due to the usage of CTR mode encryption the image should be indistinguishable from the original).

# Submission Notes

• Your hard-copy submission should include the code from parts 1 and 2 as well as the encrypted image from part 2.

• In your program file, include a header as described on the ECE 404 Homework Page.

• You must turn in two files electronically. Do not turn in files other than those listed below.

• If using Python, please denote the Python version in your code with either a shebang line (e.g. #!/usr/bin/env python3) or a comment denoting the version.

# Electronic Turn-in

turnin -c ece404 -p hw05 x931.pl AES_image.pl (if using Perl)

turnin -c ece404 -p hw04 x931.py AES_image.py (if using Python)  Email:51zuoyejun

@gmail.com