CS 160 Outlab

October 15, 2007

To Do:

The country of Hunteroen has critical data it needs to send to it's spies around the world. Hunteroen does not want the data to be intercepted and the knowledge stolen. The country of Hunteroen has hired you to write a program that will encrypt the data so that it may be transmitted more securely, and then the program will also have to decrypt the data again so you can have original data back.
All the data being transmitted are 4-digit integers. Your application should read a four digit integer entered by the user and encrypt it as follows: You will need to add the following items: Here is sample output of the program executing:

  Please give a 4 digit integer (zero to quit):
9876
The encrypted number: 4365
The decrypted number: 9876

Please give a 4 digit integer (zero to quit):
3697
The encrypted number: 6403
The decrypted number: 3697

Please give a 4 digit integer (zero to quit):
1234
The encrypted number: 189
The decrypted number: 1234

Please give a 4 digit integer (zero to quit):
0
Goodbye

Turn in

This program is due at the beginning of your next lab class (October 23rd).

Hint

When you have a number like 5893 you can break down the digits by using mod and division, then subtraction to get a new number for the next digit.