代写 algorithm Java Program Assignment: Working with checksums. This is an individual project.

Program Assignment: Working with checksums. This is an individual project.
Write a Java-class to calculate three different 16-bit checksum values for an input frame. All input frames consist of 8-bit bytes.
1. Checkum-1: The first 16-bit checksum is calculated using one’s complement addition. The input frame is divided into 16-bit units. If the frame has an odd number of bytes, pad with zeros to complete the partial sum calculation. Use the algorithm as explained in the course text book to implement the checksum calculation.
466F 28D3
+ E264 -> + 1 ->~(28D4)->D72B ___________ __________
128D3 28D4
The partial sum 28D4 is complemented to give the checksum value D72B.
2. Checksum-2: The second 16-bit checksum uses a different algorithm. For each frame byte (8-
bits/byte), xi , i=1,2,…,n, (n bytes per frame excluding the checksum bytes): f1 =0
g1 = 0
fi+1 =mod[(fi +xi),255]
gi+1 = mod[(gi + fi+1 ),255] psum=[gm fm]
Where gm contains the left 8-bits of the partial sum and fm contains the right 8-bits of the partial sum, psum. The complement of the psum is the checksum. The subscript m is the last computed f
and g. This checksum can be as good as CRC by making the following change:
3. gi+1=mod[(gi+fi+1+ki),255] (Checksum-3)
Where k is the overflow digit from the sum fi + xi .Example, if 0x12933 = fi + xi ,then the overflow digit k=1. The overflow digit can only be 0 or 1.
For each checksum answer the following:
1. Determine which checksum can detect a swap of 16 consecutive bits with another 16 consecutive bits in the input frame. The swap must occur starting on an even BYTE boundary. Answer:
2. Determine which checksum can detect 16 consecutive 0 bits converted to 16 consecutive 1 bits. This must be done starting on an even BYTE boundary. Answer:

For each checksum, the partial sum plus the checksum on the receiver side must be zero using one’s complement addition. The checksum is defined as the complement of the partial sum in each case.
Complete the Checksum class and submit the class electronically. Prepare a demonstration for your student colleagues.
public class Checksum
{
/* Frame format, where n is the number of bytes in the frame:
*/
Header consists of 14 bytes.
Trailer consists of 2 bytes. (the checksum)
Datagram consists of m bytes.
The size of the frame is inFrameSize = n = 14 + 2 + m
private byte [] inFrame; // shallow copy of the input frame.
private int inFrameSize; // total bytes in inFrame includes header + trailer
public Checksum( byte [] frame, int size )
{
// Make a SHALLOW copy of the input frame.
// Store the frame size in the first two bytes of the input frame.
}
public int getFrameSize()
{
// return the frame size = n = 14 + 2 + m bytes of the datagram.
}
public void setFrame( byte [] frame )
{
// make a SHALLOW copy of the input frame.
}
public void insertChecksum( int chksm )
{
// Insert the checksum value into the last two bytes of the input frame.
}
public int checksum1()
{
// calculate and return the first checksum
}
public int checksum2()
{
// calculate and return the second checksum
}
public int checksum3()
{
// calculate and return the third checksum
}
}
___________________________________________________________
byte indices
0-1
2-13
14-(n-3)
(n-2)-(n-1)
| Description
| Header: size of frame in bytes (2 bytes)
| Header: reserved for future purpose
| Data: datagram
| Trailer: checksum value (trailer = 2 bytes)