Due by 11:59.59pm Sunday, September 10 2017
For this assignment you will be:
We're going to start things off nice and simple. I'll recommend you create a cs241 directory in your CS account and a hw1 directory inside that.
First off, go to https://classroom.github.com/a/Fuyuolgk and create a repository in the CS 241 organization.
Click on the link and head towards the created repository. It will be called hw1-username
Go back to your CS account to the cs241 directory above, and clone the repository into this account. Refer to the github tutorials for how to do this step.
Now that you've got a place for files, go ahead and re-create the "Hello, World!" program from class. Try to compile it using gccx. Remember that this is just a shorthand for
gcc -g -pedantic -std=c99 -Wall -Wextra
So if you are playing along from home, you need to be sure that you get no compilation errors or warnings from compiling using these options. Feel free to use clang in place of gcc.
Now that you've written a C program, you need to write a Makefile to help you compile and revise it.
Be sure you have this working. If make keeps telling you everything is up to date, you can just re-save your source file or touch it to get make to run again.
If you are using emacs or vim, you can invoke make from within your editor window. Both editors can monitor the output and let you jump directly to the error reported.
Once you have this working, I'd like you to make a few changes in your first program.
Next you will create a program called rot128 that will "encrypt" files by using a rot-128 encryption algorithm. This algorithm is based on the classic text encryption scheme rot-13 which shifts each letter 13 positions in the alphabet (i.e., 'a' becomes 'n', 'b' becomes 'o', 'z' becomes 'm', etc.). Two applications of rot-13 returns you to the original. (Sadly, this has been used as actual protective encryption in commercial settings.)
Guvf vf zl irel frperg zrffntr rapbqrq va ebg13!
This is my very secret message encoded in rot13!
Instead of just rotating 13 positions, I want you to rotate by half the
allowed range of a char, that way we can encrypt and decrypt any
file on the system. Normally, a char is 8-bits, but since we can't be sure
of that, you should have the program calculate using the proper constant.
(You will need to
#include <limits.h> to use this value.)
(UCHAR_MAX + 1) / 2
Add in lines to the Makefile that compile the target rot128 and add it into both the dependencies for all and as part of the files removed by clean (being careful not to delete your source code file).
When you write your program, you should just add the above value to all characters you read in, and immediately write them out. You can use getchar() and putchar() to handle the input and output. Be aware that getchar() returns an int and you will need to do your processing on a char to have things loop around correctly. (Note that the resulting output won't be comprehensible, see the next section about how to store it.)
Be careful to not write out the EOF signal.
Your "rot128" program reads in from the user typing and writes out to the console. You can redirect the input from a file and also redirect the output to a file. Use the "<" character to redirect an input file, and the ">" to redirect output as follows:
./rot128 < inputfile > outputfile
There is a tool called diff on Unix systems that will report the differences between files. You can use this to check to see if your program is indeed working.
% vi mytext # create a text file % ./rot128 < mytext > mytext.enc # create an encrypted file % diff -q mytext mytext.enc # ask to see if they are different # -q tells it to not show the # differences Files mytext and mytext.enc differ % ./rot128 < mytext.enc > mytext.out # run your program on the DOS text % diff -q mytext mytext.out # should have no output as they are # the same
Finally, you'll be creating a program called diamond that generates a simple ASCII art diamond of variable size based on user input.
First, I want you to create a function called getdigit() that returns an integer. I.e.,
with the following properties:
Prompt the user to input an size, and then use that to create a diamond shape. The size the user inputs is the height of one of the triangles that make up the shape (the distance from a point to the center).
% ./diamond I will print a diamond for you, enter a size between 1-9: abc123 * % ./diamond I will print a diamond for you, enter a size between 1-9: 568 * *** ***** ******* ********* ******* ***** *** * %
Finally, I want you to create a file called README (note all caps and no file extension) which contains the following sections:
I have adhered to the Honor Code in this assignment
Now you should make clean to get rid of your executables and handin your folder containing 4 files (don't worry if your *.c files have different names as long as the output is the same):
Run git commit to push your changes. You should check via the github web interface to make sure that your files have been submitted properly.
Here is what I am looking for in this assignment: