CYBR 621-50 Secure System Programming and OS Theory

148 views 8:12 am 0 Comments September 4, 2023

Reminders:

  • Follow the submission instructions.
  • Remember to comment your code!

0) Random number generation. (50 pts)

Often, computer scientists, statisticians, physicists, social scientists, and mathematicians need a list of random numbers. Political pundits also find lists of random numbers useful to provide ‘statistical’ evidence of their arguments.

 

Implement a tool to generate and print a sequence of 10 random numbers.  Each random number should be an integer in the range from

0 to 100, inclusive (that means both 0 and 100 should have a chance of appearing). I do not expect you to implement your own random number generator. I expect you to use the standard way of obtaining randomness in a secure fashion.

 

$ ./grand

56 77 91 2 33 40 72 100 6 2

 

Augment your program to take a command line parameter specifying how many random numbers to generate. That is, if grand is invoked by:

$ ./grand 4

it will output 4 random numbers from 0 to 100, inclusive. Make sure your program does something sensible if the supplied argument is not a valid integer. There should not be an arbitrarily imposed upper limit to this number (in other words, do not have an artificial cap on the value of the argument).

 

Since it is easy to forget how to use programs, it is often useful to provide a well-known command line switch (or parameter) that tells the user how to invoke the program. Augment your program to recognize two more command line arguments, ‘-h’ and ‘–help’ that prints out the usage information for the program. For example,

 

$ grand -h

and

$ grand –help

should output the following usage information:

grand [-h | –help]       : output this usage message.

grand [n]                 : print out n random integers in [0,100]

 

Finally, augment your program to print out its version. Don’t forget to add this usage case to your help dialog.

$ grand –version OR -v

grand-0.0.3

1) Functions and Recursion (50 pts)

Experiment with recursion. The Fibonacci sequence is a famous naturally recursive series of numbers whose ratio approaches the Golden Ratio.

f(n) = f(n-1) + f(n-2)

Implement a program named ‘fib’ that uses recursion to calculate and print the first n Fibonacci numbers, where ‘n’ is less than or equal to 30.

 

Usage:

fib [n]

For example, ‘fib 4’ should output:

fib(0) = 0

fib(1) = 1

fib(2) = 1

fib(3) = 2

fib(4) = 3

 

Modify your program so that providing the –target or -t option will print only the nth Fibonacci number.

$ ./fib –target 3

fib(3) = 2

 

Add the ability for your program to calculate the Fibonacci sequence iteratively rather than recursively. Output should not change. If you execute your program with the name ‘ifib’ then it performs the iterative calculation.  If it is executed via ‘rfib’ or ‘fib’ it performs the recursive method of calculating.

$ ./fib –target 3

fib(3) = 2

 

$ ./ifib –target 3

fib(3) = 2

 

$ ./rfib –target 3

fib(3) = 2

 

There is an example of how to accomplish this sort of test of the program name in “C Programming Language, 2nd Edition, by Brian W. Kernighan, Dennis M. Ritchie” textbook. You can search Google for an iterative version of Fibonacci, but be sure to cite where you found it in your README.

 

  • You may want to consider using GNU getopt library for processing command line options.

 

Submission Instructions

Assignments should be submitted to the appropriate assignment Dropbox in D2L in a single zip file that conforms to the specifications described below.

 

  • Submissions MUST compile without warnings, or they cannot be graded.
  • All the files related to the assignment should be placed in a folder named assignmentX.
  • Create a ONE zip file for the folder with the following naming format:

 

assignmentX-addr.zip

 

where ‘X’ is the number of the assignment (1,2,3, …) and ‘addr’ is replaced with your Metro State email ID. For example, my submission for assignment 1 would be:

 

assignment1-ibrahim.el-shekeil.zip

 

  • Required files:
    1. ‘README’ file produced with an ASCII text editor (a text file produced using TextPad, Notepad++, nano, vim, etc, NOT Doc nor PDF) that:
      • lists your name and anyone you worked with
      • explains whether or not all problems were solved and to what degree
      • lists what sources, if any, you used to produce the code that solves the assignment problems

 

    1. ‘Makefile’[1] that controls the build process. An example of such a file is on the class website. You can reuse this file with minor modifications.
    2. Any reasonable number of C source files (.c) and header files (.h) that contain the source code for your solutions. The files should be appropriately named so that the grader can distinguish which source files correspond to which assignment problem. The assignments rarely require more than one .c file per problem.
    3. A set of test data files that show that your program works as intended.
    4. An attacker program called “attacker.c” that actively probes your program via its input channels (stdin, file I/O, cmd line arguments, environment variables, network sockets, etc.). The attacker program should behave like a normal driver program that exercise program functionalities, except that it should put more focus on revealing possible security holes, or any other areas that affect program reliability. This file should be built by your Makefile at the same time as your programming solution is built. Please take a look at the attached sample attacker programs for a reference.

 

  • Do not include any binaries, object files, messages, backup files, web pages, core dumps, etc.

Notes

  • It is to your advantage to accomplish small tasks completely in the assignment (and explain this in your README) if you are unable to finish the whole problem. It is better to be graded on a single working sub-part than a broken whole.
  • Makefiles
    • The process of compiling is often repetitive.  The process of compiling (using gcc to compile your C code to machine code) can be automated.  This automation is accomplished by using another tool called ‘make.’  A Makefile is a specially named file that tells ‘make’ how to compile C source code.  Usually, once you’ve written a Makefile and stored it in the same directory as your source code, all you have to do to build your source code is type ‘make’ at the command prompt.
    • Your Makefile should always contain a ‘clean’ target; that is, typing the following at the command line:

 

$ make clean

 

will delete object files, executables, and backup files, just leaving your source code, the README, and the Makefile.

 

    • Secondly, your Makefile should always tell gcc to compile with warnings on by passing the -Wall switch to gcc. Your submission should compile without warnings. An additional useful flag is -g, which compiles your program with debugging information.

 

Example Submission

$ cd cybr621/code

$ ls

assignment1/ assignment2/ assignment3/   …

$ cd assignment1/

$ make clean

$ ls

assignment1.c   Makefile   assignment1.h   README

$ cd ..

$ zip -r assignment1-ibrahim.el-shekeil.zip assignment1/

$ ls

assignment1/  assignment1-ibrahim.el-shekeil.zip  assignment2/   assignment3/   …

$

Now you can now upload the zip file.

 

 

Tags: , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *