Due: 2016-03-09 11:55p
A. [6 points] Martin 17
B. [6 points] Martin 18
C. [6 points] Martin 20
Rot13 is an extremely simple encryption method. It is used for low stakes obfuscation, like making it harder to read comments with spoilers in them. Follow the link to the Wikipedia article for a more in depth discussion, but the basic principle is that a character is encoded by shifting it 13 places. If the new location is past ‘z’, the character wraps around and starts at the beginning of the alphabet again. A nice feature of the scheme is that it is reversible simply by performing the same encryption process again (e.g., ‘a’ -> ‘n’ -> ‘a’). Rot13 also leaves capitalization intact and doesn’t touch spaces, numbers or special characters.
Write a function void rot13(int numlines, char * text[])
that performs in-place rot13 encoding on an array of strings. For the actual computations and comparisons, recall that you can make use of the fact that in C, char
is a numeric type. In other words, ‘a’ and the value 97 (the ASCII value of ‘a’) are interchangeable. So, given some char variable c
, you could compare it to ‘a’ (c > 'a'
), or do math with it (c + 5
).
To test this function, I would like you to pass the remainder of the arguments to your program after the name of your program. Use pointer arithmetic to pass just part of argv. After the strings have been encrypted, print them out all on the same line and separated by spaces.
Put this in a file called hw3_rot13.c
Write a program in C that counts in decimal in binary from 0 up to an input number. You should have enough tools at this point to just read the bits off of an integer, but I want you to handle this problem a little less directly. Create a new string capable of holding all of the bits of the target number. Then, for each number you should update this string to be the binary representation of the number.
To calculate the binary representation, you are welcome to either perform the count mechanically (flipping between 1s and 0s, propagating the flip when a 1 becomes a 0), or computationally (using repeated division on an integer counter). In either case, your output should look like this:
$ ./hw3_binary
Usage: ./hw3_binary <target number>
$ ./hw3_binary tardis
tardis is not a valid integer
$ ./hw3_binary 7
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
$ ./hw3_binary 24
0 00000
1 00001
2 00010
3 00011
4 00100
5 00101
6 00110
7 00111
8 01000
9 01001
10 01010
11 01011
12 01100
13 01101
14 01110
15 01111
16 10000
17 10001
18 10010
19 10011
20 10100
21 10101
22 10110
23 10111
24 11000
Note that the values are all right aligned, and use only enough room for the largest values, and that the binary numbers use only enough bits for the largest value as well.
Put this in a file called hw3_binary.c
My preference for the first part of this assignment would be that you turn it in electronically in a PDF or RTF file (not in a .doc or .docx file). however, I realize that since I’m asking you to do math the long way, I will accept handwritten submissions (provided I can actually read your handwriting).
The two programs should be handed in as separate files as indicated by their descriptions. Each function should be commented to describe its function (including extra information were requested). The top of each file should also include a comment including your name, date, assignment, compile instructions, and run instructions.
Submit the completed assignment on Moodle.