Assignment 1 CSCE 156156H Spring 2020
Instructions Follow instructions carefully, failure to do so may result in points being de ducted. You may discuss problems with your classmates at a high level, but all work must be your own. The CSE academic integrity policy is in effect see https:cse.unl.edu academicintegrity. Hand in your source files via the webhandin and be sure to verify that your programs work with the webgrader.
For those in the main section: your programs must be written in Java, should accept command line arguments as specified, execute from the command line on CSE, and output properly formatted output to the standard output. All your classes should be in the default package and your source files should have the following names:
Retire.java, Affine.java, GameReport.java
For those in the honors section: your programs must be written in PHP unless you have no prior Java experience, in which case, you should do the Java version, should accept command line arguments as specified, execute from the command line on CSE, and output properly formatted output to the standard output as specified. Your source files should have the following file names:
retire.php, affine.php, gameReport.php
Test Cases For each problem, you are required to submit two nontrivial test cases. A test case is an inputoutput pair that is known to be correctthe solution should be worked out by hand or by use of a known correct mechanism. Simply using the output of your program as the valid output is not a test case. Each test case can be put into a plain text file with the command line arguments or file contents used in the input and wellformatted expected output.
Name your test case files as follows:
,, ,
,, ,
,, ,
retireinput001.txt
retireinput002.txt
retireoutput001.txt
retireoutput002.txt
affineinput001.txt
affineinput002.txt
affineoutput001.txt
affineoutput002.txt
gameReportinput001.txt
gameReportinput002.txt
gameReportoutput001.txt
gameReportoutput002.txt
1. Program 1 Retirement Savings
A 401k plan is a type of taxqualified account for people to save for retirement. Em ployees typically have part of their pretax pay check deposited into such an account and employers may match a certain amount of those contributions. As of 2018, there is a maximum annual contribution limit of 18,500.
The money contributed to a 401k account may be invested in many different ways. While the account may grow tax free, it is not immune to inflation. To account for inflation, you can use the following formula which is the inflationadjusted rate of return.
1rate of return 1 1 inflation rate
Write a program that produces an amortization table for a 401k account. Your program will read the following inputs as command line arguments.
An initial starting balance
A monthly contribution amount well assume its the same over the life of the
savings plan
An average annual rate of return on the scale 0, 1
An average annual rate of inflation on the scale 0, 1
A number of years until retirement
Your program will then compute a monthly savings table detailing the inflationadjusted interest earned each month, contribution, and new balance. To get the monthly rate, simply divide by 12. Each month, interest is applied to the balance at this rate prior to the monthly deposit and the monthly contribution is added. Thus, the earnings compound month to month. Be sure to round appropriately, to the nearest cent so that rounding errors do not compound.
Your program will need to validate the input and quit with an error message on any potential bad inputs. For inputs
10000 500 0.09 0.012 10
your output should look something like the following:
If using Java, your program should be runnable from the command line as:
java Retire 10000 500 0.09 0.012 10 and output the results to the standard
output.
If using PHP it should be invokable from the command line as:
php retire.php 10000 500 0.09 0.012 10 and output the results to the stan
dard output.
Page 2
Month
1
2
3
4
5
6
7
8
9
…
116
117
118
119
120
Interest Balance
64.23 10564.23
67.85 11132.08
71.50 11703.58
75.17 12278.75
78.87 12857.62
82.58 13440.20
86.33 14026.53
90.09 14616.62
93.88 15210.50
678.19 106767.24
685.76 107953.00
693.37 109146.37
701.04 110347.41
708.75 111556.16
Total Interest Earned: 41556.16
Total Nest Egg: 111556.16
2. Program 2 Affine Cipher An affine cipher is an old encryption scheme that encrypts messages using the following function:
ekx ax b mod n
Where n is an integer representing the size of our character set with 0 a, b, x n 1.
For this exercise we will use the extended ASCII character set so n 256.
To encrypt a message, we choose two integers a, b to define the encryption function. For
example, if a 7 and b 10 then
ekx 7x 10 mod 256
To encrypt Hello we would use the values 72, 101, 108, 108, and 111 and encrypt each one as:
ek72 7 72 10 mod 256 2 ek101 7 101 10 mod 256 205 ek108 7 108 10 mod 256 254 ek108 7 108 10 mod 256 254 ek111 7 111 10 mod 256 19
Page 3
However, when mapped back to the extended ASCII character set, this results in some nonprintable characters. So, to ensure that it is still a plaintext file, well use hex values of the ASCII text values instead. The encrypted value would thus be: 02 cd fe fe 13 spaces added for readability and should be ignored in general
To decrypt a message we need to invert the decryption function, dkya1 ybmodn
where a1 is the inverse of a modulo n. The inverse of an integer a is the unique value a1 such that
a a1 mod n 1
In our example, with a 7 and n 256, the inverse, 71 mod256 is 183 since 7 183 mod 256 1. Note, however, that an inverse may not exist. In this particular case, no even number a will have an inverse.1
So to decrypt the first letter above, we would compute2
dk2 183 2 10 mod 256 72
Given a and n, how can we find an inverse, a1? Obviously it cannot be zero, nor can it be 1 1 is its own inverse. There is a simple algorithm the Extended Euclidean Algorithm that can solve this problem, but n 256 is small enough that a bruteforce strategy of testing all possibilities will suffice or you can precompute and store all inverse pairs if you wish.
Write a program that takes a file name as a command line argument which contains a message encrypted with an affine cipher in hexadecimal format ignore all whitespace. We will not provide the encryption or decryption keys a,b,a1, but we will provide a way to programmatically check that youve decrypted the message: the decrypted message will always contain the string Computer Science somewhere in the file.
Your task will be to bruteforce decrypt the message and print it to the standard output along with the discovered encryption keys, a,b,a1. For example, an input file may contain the following:
1To have an inverse, a must be relatively prime to n; i.e. gcda, n 1
2Take care, as negative values should wrap around back to positive ones, 8 mod 256 248 for example. However, some programming languages modulo operator may result in negative values and you may need to correct for this.
df13051a3d36cd28ea4fbfe9cd0cbfcdeae92fea
0c13ea051328cdeab1b8133d36eabf13051a3d36
cd282fea36e2b10ceab12f3628130c130559eae9
2feab1b8133d36ea36cdfecd2fbf131acd2f4c
Page 4
which, if successfully bruteforced should produce output that looks something like the following.
Message:
Computer Science is no more about computers than astronomy is about telescopes.
Affine Cipher Keys a7
a1 183
b 10
If using Java, your program should be runnable from the command line as: java Affine encrypted.txt and output the results to the standard output.
If using PHP it should be invokable from the command line as:
php affine.php encrypted.txt and output the results to the standard output.
Page 5
3. Program 3 Data Projection
Consider the CSV data below concerning video games. Each line contains a record of a game title, publisher, published year, and platform separated by commas. However, a publisher may exist without any game records Ubisoft for example, and a game may exist without being available on any platform Contra for example.
Lego Star Wars,LucasArts,2005,Xbox
Lego Star Wars,LucasArts,2005,PlayStation 2
Lego Star Wars,LucasArts,2005,PC
Lego Star Wars,LucasArts,2005,Mac
Tie Fighter,LucasArts,1994,PC
XWing vs Tie Fighter,LucasArts,1997,PC
,Sony Computer Entertainment,,
,Square Enix,,
,Sega,,
Legend of Zelda,Nintendo,1987,NES
Super Mario Brothers,Nintendo,1985,NES
Zelda II: The Adventure of Link,Nintendo,1988,NES
Tetris,Nintendo,1989,Game Boy
Super Mario Land,Nintendo,1989,Game Boy
GTA IV,Rockstar Games,2008,Xbox 360
GTA IV,Rockstar Games,2008,PC
GTA 3,Rockstar Games,,
GTA 2,Rockstar Games,,
GTA,Rockstar Games,,
,Blizzard Entertainment,,
Mega Man 3,Capcom,1990,NES
Mega Man 4,Capcom,,
Contra,Capcom,,
,Atari,,
Portal,Valve,2007,PlayStation 3
Portal,Valve,2007,PC
Portal,Valve,2007,Xbox 360
Portal 2,Valve,2011,Xbox 360
Portal 2,Valve,2011,PlayStation 3
Portal 2,Valve,2011,PC
Portal 2,Valve,2011,Mac
Katamari Damacy,Namco,2004,PlayStation 2
Out of this World,Delphine Software,1992,PC
Out of this World,Delphine Software,1992,Super NES
Assassins Creed,Ubisoft,2007,Xbox 360
,Ubisoft,,
You will write a program to process such a file whose pathname is provided as a command line argument and produce two reports.
A sorted list of publishers sorted alphabetically along with a count of the number of games they have published.
A sorted list of games sorted alphabetically along with a count of the number of platforms they are available on.
For the example above, the two reports would look something like the output below.
Publisher Game Counts
Atari 0
Page 6
Blizzard Entertainment 0
Capcom 3
Delphine Software 1
LucasArts 3
Namco 1
Nintendo 5
Rockstar Games 4
Sega 0
Sony Computer Entertainment 0
Square Enix 0
Ubisoft 1
Valve 2
Game Platform Counts
Assassins Creed 1
Contra 0
GTA 0
GTA 2 0
GTA 3 0
GTA IV 2
Katamari Damacy 1
Legend of Zelda 1
Lego Star Wars 4
Mega Man 3 1
Mega Man 4 0
Out of this World 2
Portal 3
Portal 2 4
Super Mario Brothers 1
Super Mario Land 1
Tetris 1
Tie Fighter 1
XWing vs Tie Fighter 1
Zelda II: The Adventure of Link 1
If using Java, your program should be runnable from the command line as:
java GameReport inputFile.csv and output the results to the standard output.
If using PHP it should be invokable from the command line as:
php gameReport.php inputFile.csv and output the results to the standard out
put.
Page 7