program filename
for this assignment: packets.cpp
This assignment is from computer
networks. The idea is to simulate some of the ideas in computer networks. In
this assignment you will explore the idea of creating network packets and encryption.
Any message, including an e-mail message, is divided into several packets by
the sending computer before it can be transported over the network to the
destination computer. In addition, the sending computer may encrypt the message
within the packets.
A packet contains the senders
user name, the receivers user name, 10 characters of data from the message, a
sequence number, and a number indicating the total number of packets to make up
the message (The sample at the end will clarify these points).
The encryption function is
provided here:
/* Name: Encrypt
Description: A simple encryption function that does the following:
converts spaces to '_',
converts '\n' to '$',
converts '\0' to '@',
converts unknown chars to '*',
converts all other characters
to their mirror opposite in the
ASCII table
Parameter: character to encrypt
Result: encrypted character
*/
char Encrypt(char a)
{
if (a
== '_')
return '_';
else
if (a == '@')
return '$';
else if (a == '@')
return '@';
else
if (a < 0)
return '*';
for (int x = 0; a != x; x++) {
if ( (a-33) == x)
return (126-x);
}
return
'*';
}
You will need to put this
function and its prototype in your program and use it to encrypt the characters
in the data
portion of the packet. Encryption is the process of converting your data into a
secret coded data.
The input file for this program (packets.in) contains a simple text message where the first
line in the file is the “From” address of the form username@domainname. The
second line in the file is the “To” address in the same format. In both cases,
the username must be 8 characters long. After the second line, the message
begins. You may type anything in body of the message (It should be less than
1000 characters or about ½ a page).
The output should be placed in
the file packets.out. The output
consist of a 2 tables. Both tables have the headings “From”, “To”, “Data”,
“Seq”, and “Tot” using appropriately sized column
widths. Each row of the table is a packet created from the input message. The
first table contains the packets before encryption. The second table contains
the packets after the data portion is encrypted. See the Sample for an example
of this output.
To make the packets more
readable, you should translate ‘
‘(space), ‘\n’(newline), ‘\0’(null character) to ‘_’, ‘$’, and ‘@’ respectively. This should be done as
you read the input file and create packets.
The following are sample inputs
and outputs. Note that the input must be in a file called packets.in.
bboop123@spelman.edu
friend12@earthlink.net
Hello World
Betty
Original Packets
From To
Data Seq Tot
bboop123 friend12 $Hello_Wo 0 3
bboop123 friend12 rld$$Betty 1 3
bboop123 friend12 $$$ 2 3
Encrypted Packets
From To
Data Seq Tot
bboop123 friend12 $W:330_H0 0 3
bboop123 friend12 -3;$$]:++& 1 3
bboop123 friend12 $$$ 2 3
Notice how the Encrypted packets have strange characters
substituted for the original input characters. This is done by the Encrypt
function above
The string type has some features that can help you. Refer
to class notes for sample uses of string variables (objects).
The evaluation of the assignment will be focused on your use
of functions in your design and implementation. The standard criteria will also
be evaluated.
When you have completed the assignment, be sure you are in the directory where you source code files (.cpp or .cc files) are present:
% turnin cis121a prog3 packets.cpp