Reference no: EM133105211
Assignment A: Implement "diff" in assembly
For this exercise you will implement the Unix "diff" program in assembly. The purpose of the diff program is to compare two files line by line and show all the differences between them. As a sample output, consider the following two files:
Hi, this is a testfile. Hi, this is a testfile.
Testfile 1 to be precise. Testfile 2 to be precise.
The resulting output of diff is then:
$ diff testfile1 testfile2
2c2
< Testfile 1 to be precise.
---
> Testfile 2 to be precise.
As you can see it tells us that the second line is different (2c2 means that line 2 in the original has been changed to become line 2 in the new file). For more information on how the diff command works, please check the diff manuals (type man diff in a terminal or search for man diff online)
For this assignment your program will have to be able to do the following:
Implement a line-by-line comparison version of diff. This means it is not required to have the a and d outputs that the real diff offers. Only the changes will suffice, though we encourage you to also try the detection of addition and deletion of lines.
Implement at least the -i and -B options that diff offers (ignore case and ignore blank lines, respectively). For more details, read the diff man page or try some test cases with an existing diff implementation.
Note : It is not required that you read text from a file or the standard input. It is allowed for you to hardcode the texts you are comparing in your source. If you do this however, the student assistants will change this hardcoded text to confirm that your program works for different texts as well. Similarly, you do not need to read the -i and -B options from the command line. It is allowed to hardcode these as boolean values at the top of your source code, but student assistants will ask you to demonstrate both options (even combined).
Assignment B: Implement a hashing function
Important: you can only get points for either assignment 5a or assignment 5b, not both. Please read both assignments before picking which you want to attempt.
For this assignment, implement a program to calculate a hash such as SHA-1, SHA-256, MD4, MD5, or any other hash you like, of the input given to the program. If you do not know what a hash function is, Google a bit first.
Exercise:
Choose a well known hashing algorithm, and write a program that calculates and prints the hash of the input given to the program. (From standard input or from a file.)
Optional help from our side for SHA-1:
Read the Wikipedia page about SHA-14 (especially the pseudo code). As you will see, the algo- rithm has to split up the data up in 512-bit chunks, and then process each chunk separately. In this simplified exercise, you will only implement the function to process a chunk. The rest of the code is provided by us.
Our part of the code can be downloaded from Canvas. You can combine this with your own code by adding "./sha1 test64.so"5 as another parameter to gcc. Our code does everything until and including the line "break chunk into sixteen . . ." in the pseudo code on Wikipedia. The command used to compile your code could like something like this: gcc -o test my_sha1_chunk.s ./sha1_test64.so -no-pie
Your part of the code should not have a main function, but instead have a sha1 chunk function, which will be called by our part of the code. This sha1 chunk function takes two parameters: First, the address of h0 (h1, h2, etc. are stored directly after h0).
Second, the address of the first 32-bit word of an array of 80 32-bit words. The first sixteen of this array are set to the sixteen 32-bit words the chunk contains (which are called w[0] till w[15]). Your function should modify h0 till h4 as described in the pseudo code.
When you execute the combined program, our part of the code prints a lot of information on what is happening, and when your function is called. It displays the result of your function, and whether that is correct or not. You can of course print more debugging information from your own function using printf.