You are on page 1of 30

Department of Computer Science and Engineering

ALLENHOUSE INSTITUTE OF TECHNOLOGY

Department
Of
Computer Science & Engineering
Computer Network Lab Manual
For the Academic Year 201 -1
(In accordance with UPTU syllabus)

Faculty In-charge

Allenhouse Institute of Technology, Kanpur

Head of Department

Department of Computer Science and Engineering

Table of Content
S. No

List of Experiment

1.

Study of different types of Network cables and


Practically implement the cross-wired cable and
straight through cable using clamping tool.

2.

Study of Network Devices in Detail.

3.

Study of network IP.

4.

Connect the computers in Local Area Network.

5.

Implementation of the Data Link Layer framing

Page No. Date

Signature

method such bit stuffing in C.


6.

Implementation of the Data Link Layer framing


method such as character stuffing in C.

7.

Implementation of CRC in C

8.

Implementation of a Hamming (7,4) code to limit the


noise.. Implementation will be in C

9.

To Implement 2 dimensional parity checker in C

10.

Implementation of LZW compression algorithm in C

11.

Write a program in C to encrypt 64-bit text using DES


algorithm

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

EXPERIMENT-1
Aim: Study of different types of Network cables and practically implement the cross-wired cable and
straight through cable using clamping tool.

Requirements: RJ-45 connector, Climping Tool, Twisted pair Cable


Procedure: To do these practical following steps should be done:
1.Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very careful at
this point, as to not nick or cut into the wires, which are inside. Doing so could alter the characteristics
of your cable, or even worse render is useless. Check the wires, one more time for nicks or cuts. If there
are any, just whack the whole end off, and start over.
2.Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand. You do
not want the wires to become untwisted down inside the jacket. Category 5 cable must only have 1/2 of
an inch of 'untwisted' wire at the end; otherwise it will be 'out of spec'. At this point, you obviously
have ALOT more than 1/2 of an inch of un-twisted wire.
3.You have 2 end jacks, which must be installed on your cable. If you are using a pre-made cable, with
one of the ends whacked off, you only have one end to install - the crossed over end. Below are two
diagrams, which show how you need to arrange the cables for each type of cable end. Decide at this
point which end you are making and examine the associated picture below.
Diagram shows you how to prepare Cross wired connection

Diagram shows you how to prepare straight through wired connection


Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

EXPERIMENT-2
Aim: Study of following Network Devices in Detail

Repeater

Hub

Switch

Bridge

Router

Gate Way

Requirements: No software or hardware needed.


Procedure: Following should be done to understand this practical.
1. Repeater: Functioning at Physical Layer. A repeater is an electronic device that receives a signal and
retransmits it at a higher level and/or higher power, or onto the other side of an obstruction, so that the
signal can cover longer distances. Repeater have two ports, so cannot be used to connect for more than
two devices
2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator is a device for
connecting multiple twisted pair or fiber optic Ethernet devices together and making them act as a
single network segment. Hubs work at the physical layer (layer 1) of the OSI model. The device is a
form of multiport repeater. Repeater hubs also participate in collision detection, forwarding a jam signal
to all ports if it detects a collision.
3. Switch: A network switch or switching hub is a computer networking device that connects network
segments. The term commonly refers to a network bridge that processes and routes data at the data link
layer (layer 2) of the OSI model. Switches that additionally process data at the network layer (layer 3
and above) are often referred to as Layer 3 switches or multilayer switches.
4. Bridge: A network bridge connects multiple network segments at the data link layer (Layer 2) of the
OSI model. In Ethernet networks, the term bridge formally means a device that behaves according to
the IEEE 802.1D standard. A bridge and switch are very much alike; a switch being a bridge with
numerous ports. Switch or Layer 2 switch is often used interchangeably with bridge. Bridges can
analyze incoming data packets to determine if the bridge is able to send the given packet to another
segment of the network.

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

5. Router: A router is an electronic device that interconnects two or more computer networks, and
selectively interchanges packets of data between them. Each data packet contains address information
that a router can use to determine if the source and destination are on the same network, or if the data
packet must be transferred from one network to another. Where multiple routers are used in a large
collection of interconnected networks, the routers exchange information about target system addresses,
so that each router can build up a table showing the preferred paths between any two systems on the
interconnected networks.
6. Gate Way: In a communications network, a network node equipped for interfacing with another
network that uses different protocols.
A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
A protocol translation/mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

EXPERIMENT-3
Aim: Study of network IP
Classification of IP address
Sub netting
Super netting

Requirements: NA
Procedure: Following is required to be study under this practical.
Classification of IP address
As show in figure we teach how the IP addresses are classified and when they are used.
Class
Class A
Class B
Class C
Class D
Class E

Address Range
1.0.0.1 to 126.255.255.254
128.1.0.1 to 191.255.255.254
192.0.1.1 to 223.255.254.254
224.0.0.0 to 239.255.255.255
240.0.0.0 to 254.255.255.254

Supports
Supports 16 million hosts on each of 127 networks.
Supports 65,000 hosts on each of 16,000 networks.
Supports 254 hosts on each of 2 million networks.
Reserved for multicast groups.
Reserved.

Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify subnet address.
Super netting
Why we develop super netting and How to calculate supernet mask and how to identify supernet
address.

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

EXPERIMENT-4
Aim: Connect the computers in Local Area Network.
Requirements: NA
Procedure: On the host computer
On the host computer, follow these steps to share the Internet connection:
1. Log on to the host computer as Administrator or as Owner.
2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click the connection that you use to connect to the Internet. For example, if you connect to the
Internet by using a modem, right-click the connection that you want under Dial-up / other network
available.
6. Click Properties.
7. Click the Advanced tab.
8. Under Internet Connection Sharing, select the Allow other network users to connect through this
computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up connection whenever a
computer on my network attempts to access the Internet check box if you want to permit your computer
to automatically connect to the Internet.
10. Click OK. You receive the following message:
When Internet Connection Sharing is enabled, your LAN adapter will be set to use IP address
192.168.0.1. Your computer may lose connectivity with other computers on your network. If these other
computers have static IP addresses, it is a good idea to set them to obtain their IP addresses
automatically. Are you sure you want to enable Internet Connection Sharing?
11. Click Yes.The connection to the Internet is shared to other computers on the local area network
(LAN).The network adapter that is connected to the LAN is configured with a static IP address of
192.168.0.1 and a subnet mask of 255.255.255.0
On the client computer
To connect to the Internet by using the shared connection, you must confirm the LAN adapter IP
configuration, and then configure the client computer. To confirm the LAN adapter IP configuration,
follow these steps:
1. Log on to the client computer as Administrator or as Owner.
Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

2. Click Start, and then click Control Panel.


3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click Local Area Connection and then click Properties.
6. Click the General tab, click Internet Protocol (TCP/IP) in the connection uses the following items
list, and then click Properties.
7. In the Internet Protocol (TCP/IP) Properties dialog box, click Obtain an IP address automatically (if
it is not already selected), and then click OK.
Note: You can also assign a unique static IP address in the range of 192.168.0.2 to 192.168.0.254. For
example, you can assign the following static IP address, subnet mask, and default gateway:
8. IP Address 192.168.31.202
9. Subnet mask 255.255.255.0
10. Default gateway 192.168.31.1
11. In the Local Area Connection Properties dialog box, click OK.
12. Quit Control Panel.

Allenhouse Institute of Technology, Kanpur

Department of Computer Science and Engineering

EXPERIMENT-5
Aim: Implementation of the Data Link Layer framing method such as bit stuffing in C
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Theory
Timing is recovered from the signal itself (by the carrier if the signal is analog, or by regular transitions
in the data signal or by a separate clock line if the signal is digital). Scrambling is often used to ensure
frequent transitions needed. The data transmitted may be of any bit length, but is often constrained by
the frame transfer protocol (data link or MAC protocol).
Bit-oriented framing only assumes that bit synchronization has been achieved by the underlying
hardware, and the incoming bit stream is scanned at all possible bit positions for special patterns
generated by the sender. The sender uses a special pattern (a flag pattern) to delimit frames (one flag at
each end), and has to provide for data transparency by use of bit stuffing (see below). A commonly used
flag pattern is HDLC's 01111110 flag as shown in Fig. 3.1.7. The bit sequence 01111110 is used for
both preamble and postamble for the purpose of synchronization. A frame format for bit-oriented
synchronous frame is shown in Fig. 3.1.8. Apart from the flag bits there are control fields.
This field contains the commands, responses and sequences numbers used to maintain the data flow
accountability of the link, defines the functions of the frame and initiates the logic to control the
movement of traffic between sending and receiving stations.
110100010101000001111100101010
01111110 110100010101000001101100101010 01111110
Specific pattern

Specific pattern

to represent

to represent

start of frame

end of frame

Summary of the approach:


Initially 1 or 2 synchronization characters are sent
Data characters are then continuously sent without any extra bits
At the end, some error detection data is sent
Advantages:
Allenhouse Institute of Technology, Kanpur

10

Department of Computer Science and Engineering

Much less overhead


No overhead is incurred except for synchronization characters
Disadvantages:
No tolerance in clock frequency is allowed
The clock frequency should be same at both the sending and receiving ends
Bit stuffing: If the flag pattern appears anywhere in the header or data of a frame, then the receiver may
prematurely detect the start or end of the received frame. To overcome this problem, the sender makes
sure that the frame body it sends has no flags in it at any position (note that since there is no character
synchronization, the flag pattern can start at any bit location within the stream). It does this by bit
stuffing, inserting an extra bit in any pattern that is beginning to look like a flag. In HDLC, whenever 5
consecutive 1's are encountered in the data, a 0 is inserted after the 5th 1, regardless of the next bit in
the data as shown in Fig. 3.1.9. On the receiving end, the bit stream is piped through a shift register as
the receiver looks for the flag pattern. If 5 consecutive 1's followed by a 0 is seen, then the 0 is dropped
before sending the data on (the receiver destuffs the stream).
If 6 1's and a 0 are seen, it is a flag and either the current frame are ended or a new frame is started,
depending on the current state of the receiver. If more than 6 consecutive 1's are seen, then the receiver
has detected an invalid pattern, and usually the current frame, if any, is discarded.
11011111111100111111110001111111000
01111110

11011111011110011111011100011111011000

01111110

ALGORITHM
main()
{
char str[100],str1[200];
int n=0,i,j;
cout<<"Enter bit sequence: ";
gets(str);
for(i=0,j=0;i<strlen(str);i++)
{
str1[i+j]=str[i];
if(str[i]=='1')
n++;
else
n=0;
Allenhouse Institute of Technology, Kanpur

11

Department of Computer Science and Engineering

if(n==5)
{
j++;
str1[i+j]='0';
n=0;
}
}
str1[i+j]=NULL;
cout<<str1;
IMPORTANT QUESTIONS
1. What is bit-stuffing? Why is it used?
2. What is the concept of bit flags?
3. Why is 01111110 chosen for

Allenhouse Institute of Technology, Kanpur

12

Department of Computer Science and Engineering

EXPERIMENT-6
Aim: Implementation of the Data Link Layer framing method such as character stuffing in C.
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Theory:
The first framing method uses a field in the header to specify the number of characters in the frame.
When the data link-layer sees the character count, it knows how many characters follow, and hence
where the end of the frame is. This technique is shown in Fig. for frames of size 6, 4, and 8 characters,
respectively. The trouble with this algorithm is that the count can be garbled by a transmission error.
For example, if the character count of 4 in the second frame becomes 5, as shown in Fig., the
destination will get out of synchronization and will be unable to locate the start of next frame. Even if
the checksum is incorrect so the destination knows that the frame is bad, it still had no way of telling
where the next frame starts. Sending a frame back to the source and asking for retransmission does not
help either, since the destination doesnt know how many characters to skip over to the start of re
transmission. For this reason the character count method is rarely used. Character-oriented framing
assumes that character synchronization has already been achieved by the hardware. The sender uses
special characters to indicate the start and end of frames, and may also use them to indicate header
boundaries and to assist the Receiver gain character synchronization. Frames must be of an integral
character length.
Most commonly, a DLE (data link escape) character is used to signal that the next character is a control
character, with DLE SOH (start of header) used to indicate the start of the frame (it starts with a
header), DLE STX (start of text) used to indicate the end of the header and start of the data portion, and
DLE ETX (end of text) used to indicate the end of the frame.
ACB
DLE STX A C B DLE ETX
A serious problem occurs with this method when binary data, such as object program are being
transmitted. It may easily happen when the characters for DLE STX or DLE ETX occur in the data,
which will interfere with the framing. One way to overcome this problem is to use character stuffing
discussed below.
Allenhouse Institute of Technology, Kanpur

13

Department of Computer Science and Engineering

When a DLE character occurs in the header or the data portion of a frame, the sender must somehow let
the receiver know that it is not intended to signal a control character.
The sender does this by inserting an extra DLE character after the one occurring inside the frame, so
that when the receiver encounters two DLEs in a row, it immediately deletes one and interpret the other
as header or data. This is shown in Fig. Note that since the receiver has character synchronization, it
will not mistake a DLE pattern that crosses a byte boundary as a DLE signal
A B C DLESTX D
DLESOH DLESTX A B C ESC DLESTX D DLEEOT DLEEOH
The main disadvantage of this method is that it is closely tied to 8-bit characters in general and the
ASCII character code in particular. As networks grow, this disadvantage of embedding the character
code in framing mechanism becomes more and more obvious, so a new technique had to be
developed to allow arbitrary sized character.
ALGORITHM
char str[100],str1[200];
int n=0,i,j;
cout<<"Enter character sequence: "; gets(str);
if (char==DLESTX,EOTSTX,esc)
for(i=0,j=0;i<strlen(str);i++)
{
str1[i+j]=str[i];
if(str[i]=='esc esc') n++;
else
n=0;
if(n==5)
{
j++;
str1[i+j]='esc stx/EOTSTX'; n=0;
}
}
str1[i+j]=NULL;
cout<<str1;
IMPORTANT QUESTIONS
Allenhouse Institute of Technology, Kanpur

14

Department of Computer Science and Engineering

1. What is character stuffing ? Why is it used?


2. What is flag? Whare is it padded?
3. What are ecs characters? How many esc characters are added if 2 stx words occur in data?

Allenhouse Institute of Technology, Kanpur

15

Department of Computer Science and Engineering

EXPERIMENT-7
Aim: Implementation of CRC In C.
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Theory:
Cyclic Redundancy Check
Error detection is important whenever there is a non-zero chance of your data getting corrupted.
Whether it's an Ethernet packet or a file under the control of your application, you can add a piece of
redundant information to validate it.
The simplest example is a parity bit. Many computers use one parity bit per byte of memory. Every
time the byte gets written, the computer counts the number of non-zero bits in it. If the number is ven, it
sets the ninth parity bit, otherwise it clears it. When reading the byte, the computer counts the number
of non-zero bits in the byte, plus the parity bit. If any of the nine bits is flipped, the sum will be odd and
the computer will halt with a memory error. (Of course, if two bits are flipped--a much rarer
occurrence--this system will not detect it.) For messages longer than one byte, you'd like to store more
than one bit of redundant information. You might, for instance, calculate a checksum. Just add together
all the bytes in the message and append (or store somewhere else) the sum. Usually the sum is
truncated to, say, 32 bits. This system will detect many types of corruption with a reasonable
probability. It will, however, fail badly when the message is modified by inverting or swapping groups
of bytes. Also, it will fail when you add or remove null bytes.
Calculating a Cyclic Redundancy Check is a much more robust error checking algorithm.
Optimized CRC Calculation
The main trick in optimizing the CRC calculation is to operate on bytes rather than bits. Look at the top
8 bits of the CRC register. Scan this byte from left to right. Every time you find a non-zero bit, you
XOR the key into the register at a bit offset such that this bit is turned off by the top invisible bit of the
key. (Notice that this operation can modify the remaining bits in the byte you are scanning.) XORing is
like addition, it is associative and you can do it in any order. So you can XOR together a bunch of
shifted keys corresponding to a given byte and store it for later. This is simply a section of the slow
CRC algorithm applied to our pre-calculation:
Allenhouse Institute of Technology, Kanpur

16

Department of Computer Science and Engineering

Designing CRC polynomials


The selection of generator polynomial is the most important part of implementing the CRC algorithm.
The polynomial must be chosen to maximise the error detecting capabilities while minimising overall
collision probabilities.
The most important attribute of the polynomial is its length (the number of the highest nonzero
coefficient), because of its direct influence of the length of the computed checksum.
The most commonly used polynomial lengths are: 9
bits (CRC-8)
17 bits (CRC-16)
33 bits (CRC-32)
65 bits (CRC-64)
The design of the CRC polynomial depends on what is the maximum total length of the block to be
protected (data + CRC bits), the desired error protection features, and the type resources for
implementing the CRC as well as the desired performance.

Algorithm
#ifndef CM_DONE
#define CM_DONE
#ifndef DONE_STYLE
typedef unsigned bool;
typedef unsigned long ulong;
typedef unsigned char*p_ubyte; #ifndef TRUE
#define FALSE 0
#define TRUE 1
#endif
#define P_(A) A
#endif
/*
crc model abstract type the following type stores the context of an
executing instance of the model algorithm.most of the fieldsare
Allenhouse Institute of Technology, Kanpur

17

Department of Computer Science and Engineering

model parameters which must be set before the first initializing call
to cm_ini
*/
typedef struct
{
int cm_width;

//width in bits

ulong cm_poly;

//algorithm's polynomial

ulong cm_init;

//initial register value

bool cm_refin;

//this parameter reflects i/p bytes

bool cm_refot;

//this parameter reflects o/p crc

ulong cm_xorot;

//this parameter xors o/p crc

ulong cm_reg;

//context during execution

}cm_t;

//name of structure

typedef cm_t *p_cm_t;


// Following functions animate the cm_t abstraction
void cm_ini

P_((p_cm_t

p_cm));

//Following
functions initialize crc model argument instance.
//All parameter fields
must be set before calling this function.
void cm_nxt
P_((p_cm_t p_cm,int ch));
void cm_blk
P_((p_cm_t p_cm,p_ubyte blk_adr,ulong blk_len));
ulong cm_crc P_((p_cm_t p_cm));
ulong cm_tab P_((p_cm_t p_cm,int index));
#endif
IMPORTANT QUESTIONS
1. What is CRC and why it is used?
2. In which layer of the OSI model is the CRC implemented?
3. What division type is used in the CRC check?
4. How are the CRC polynomials generated?

EXPERIMENT-8
Aim: Implementation of a Hamming (7,4) code to limit the noise. We have to code the 4 bit data in to
7 bit data by adding 3 parity bits. Implementation will be in C..

Allenhouse Institute of Technology, Kanpur

18

Department of Computer Science and Engineering

Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Theory:
Concept of error-correction can be easily understood by examining the simplest case of single-bit
errors. As we have already seen that a single-bit error can be detected by addition of a parity bit
(VRC) with the data, which needed to be send. A single additional bit can detect error, but its not
sufficient enough to correct that error too. For correcting an error one has to know the exact position
of error, i.e. exactly which bit is in error (to locate the invalid bits). For example, to correct a single-bit
error in an ASCII character, the error correction must determine which one of the seven bits is in error.
To this, we have to add some additional redundant bits.
To calculate the numbers of redundant bits (r) required to correct d data bits, let us find out the
relationship between the two. So we have (d+r) as the total number of bits, which are to be
transmitted; then r must be able to indicate at least d+r+1 different values. Of these, one value means
no error, and remaining d+r values indicate error location of error in each of d+r locations. So, d+r+1
states must be distinguishable by r bits, and r bits can indicates 2r states. Hence, 2r must be greater
than d+r+1.
2r >= d+r+1
The value of r must be determined by putting in the value of d in the relation. For example, if d is 7,
then the smallest value of r that satisfies the above relation is 4. So the total bits, which are to be
transmitted is 11 bits (d+r = 7+4 =11).
Now let us examine how we can manipulate these bits to discover which bit is in error. A technique
developed by R.W.Hamming provides a practical solution. The solution or coding scheme he
developed is commonly known as Hamming Code. Hamming code can be applied to data units of any
length and uses the relationship between the data bits and redundant bits as discussed
P7
D6
P: PARITY BIT

D5

D4

D3

P2

P1

D: DATA BIT
Basic approach for error detection by using Hamming code is as follows:
To each group of m information bits k parity bits are added to form (m+k) bit code as shown in
Fig. 3.2.8.
Allenhouse Institute of Technology, Kanpur

19

Department of Computer Science and Engineering

Location of each of the (m+k) digits is assigned a decimal value.


The k parity bits are placed in positions 1, 2, ..., 2k-1 positions.K parity checks are performed on
selected digits of each codeword.
At the receiving end the parity bits are recalculated. The decimal value of the k parity bits provides
the bit-position in error, if any

Figure shows how hamming code is used for correction for 4-bit numbers (d4d3d2d1) with the help of
three redundant bits (r3r2r1). For the example data 1010, first r1 (0) is calculated considering the parity
of the bit positions, 1, 3, 5 and 7. Then the parity bits r2 is calculated considering bit positions 2, 3, 6
and 7. Finally, the parity bits r4 is calculated considering bit positions 4, 5, 6 and 7 as shown. If any
corruption occurs in any of the transmitted code 1010010, the bit position in error can be found out by
calculating r3r2r1 at the receiving end. For example, if the received code word is 1110010, the
recalculated value of r3r2r1 is 110, which indicates that bit position in error is 6, the decimal value of
110.
Algorithm
int getcheckbits(int n, int k)
Allenhouse Institute of Technology, Kanpur

20

Department of Computer Science and Engineering

{
return n-k;
}
int checkblocklength(int n, int q)
{
if(n == pow(2,q)-1)
return 1;
else return 0;
}
int getmessagebits(int n, int q)
{
return n-q;
}
void main()
{
int n=7,k=4,dmin=3;
clrscr();
if(checkblocklength(n,getcheckbits(n,k)))
if(getmessagebits(n,getcheckbits(n,k)))
{
cout<<"Block Length is correct."<<endl;
cout<<"Number of errors detected = "<<dmin-1;
}
Important Questions
1.

What is hamming distance? How is it measured?

2. What are the positions of parity bits? On what basis are they? Decided?
3. How is the error corrected in hamming code

EXPERIMENT-9
Aim: To Implement 2 Dimensional Parity Checker In C
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Allenhouse Institute of Technology, Kanpur

21

Department of Computer Science and Engineering

Theory:
Performance can be improved by using two-dimensional parity check, which organizes the block of bits
in the form of a table. Parity check bits are calculated for each row, which is equivalent to a simple
parity check bit. Parity check bits are also calculated for all columns then both are sent along with the
data. At the receiving end these are compared with the parity bits calculated on the received data

Two- Dimension Parity Checking increases the likelihood of detecting burst errors. As we have shown
in Fig. that a 2-D Parity check of n bits can detect a burst error of n bits. A burst error of more than n
bits is also detected by 2-D Parity check with a high probability.
There is, however, one pattern of error that remains elusive. If two bits in one data unit are damaged
and two bits in exactly same position in another data unit are also damaged, the 2-D Parity check
checker will not detect an error. For example, if two data units: 11001100 and 10101100. If first and
second from last bits in each of them is changed, making the data units as 01001110 and 00101110, the
error cannot be detected by 2-D Parity check.

Algorithm:
1. input one bit of streams from user
2. check it to be of at least one byte
3. padd one extra bit in the bit stream depending on number of odd / even ones
4. now check it t be of the same
5. if
6. {
Allenhouse Institute of Technology, Kanpur

22

Department of Computer Science and Engineering

7. same == no error
8. else
9. error at bit stream x

Important Questions
Question-1: Explain the parity checker?
Question-2: Explain about the types of error detected by parity checker?
Question-3: Explain the concept of padding extra bit?

EXPERIMENT-10
Aim: Implementation of LZW compression algorithm in C.
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Allenhouse Institute of Technology, Kanpur

23

Department of Computer Science and Engineering

Theory: Lempel-Ziv-Welch (LZW) Algorithm


The LZW algorithm is a very common compression technique.
Suppose we want to encode the Oxford Concise English dictionary which contains about 159,000
entries. Why not just transmit each word as an 18 bit number?
Problems:
Too many bits,
everyone needs a dictionary,
only works for English text.
Solution: Find a way to build the dictionary adaptively.
Original methods due to Ziv and Lempel in 1977 and 1978. Terry Welch improved the scheme in
1984 (called LZW compression).
It is used in UNIX compress -- 1D token stream (similar to below)
It used in GIF comprerssion -- 2D window tokens (treat image as with Huffman Coding
Above).
The LZW Compression Algorithm can summarised as follows:
w = NIL;
while ( read a character k )
{
if wk exists in the dictionary
w = wk;
else
add wk to the dictionary;
output the code for w;
w = k;
}
Original LZW used dictionary with 4K entries, first 256 (0-255) are ASCII codes.
Example:
Input string is "^WED^WE^WEE^WEB^WET".
w k output index symbol
----------------------------------------NIL ^
^ W ^ 256 ^W
W E W 257 WE
E D E 258 ED
Allenhouse Institute of Technology, Kanpur

24

Department of Computer Science and Engineering

D ^ D 259 D^
^W
^W E 256 260 ^WE
E ^ E 261 E^
^W
^W E
^WE E 260 262 ^WEE
E^
E^ W 261 263 E^W
WE
WE B 257 264 WEB
B ^ B 265 B^
^W
^W E
^WE T 260 266 ^WET
T EOF T
A 19-symbol input has been reduced to 7-symbol plus 5-code output. Each code/symbol will
need more than 8 bits, say 9 bits.
Usually, compression doesn't start until a large number of bytes (e.g., > 100) are read in.
The LZW Decompression Algorithm is as follows:
read a character k;
output k;
w = k;
while ( read a character k )
/* k could be a character or a code. */
Allenhouse Institute of Technology, Kanpur

25

Department of Computer Science and Engineering

{
entry = dictionary entry for k;
output entry;
add w + entry[0] to dictionary;
w = entry;
}
Example (continued):
Input string is "^WED<256>E<260><261><257>B<260>T".
w k output index symbol
------------------------------------------^^
^ W W 256 ^W
W E E 257 WE
E D D 258 ED
D <256> ^W 259 D^
<256> E E 260 ^WE
E <260> ^WE 261 E^ <260> <261> E^ 262 ^WEE
<261> <257> WE 263 E^W
<257> B B 264 WEB
B <260> ^WE 265 B^
<260> T T 266 ^WET
Problem: What if we run out of dictionary space?
Solution 1: Keep track of unused entries and use LRU
Solution 2: Monitor compression performance and flush dictionary when performance is
poor.
Implementation Note: LZW can be made really fast; it grabs a fixed number of bits from input
stream, so bit parsing is very easy. Table lookup is automatic.

Allenhouse Institute of Technology, Kanpur

26

Department of Computer Science and Engineering

ALGORITHM
w := NIL;
while (there is input)
{
K := next symbol from input;
if (wK exists in the dictionary)
{
w := wK;
}
else
{
output (index(w));
add wK to the dictionary;
w := K;
}
}
Important Questions:
Question-1: What is LZW? Why is it used?
Question-2: What is the difference between LZW and LZ77?
Question-3: What is the efficiency of data compression by LZW?

EXPERIMENT-11
Aim: Program in C to encrypt 64-bit text using DES algorithm
Requirements

Computer with PENTIUM IV/ DUAL CORE PROCESSORS

TURBO C

Allenhouse Institute of Technology, Kanpur

27

Department of Computer Science and Engineering

Theory:
DES (the Data Encryption Standard) is a symmetric block cipher developed by IBM. The algorithm
uses a 56-bit key to encipher/decipher a 64-bit block of data. The key is always presented as a 64-bit
block, every 8th bit of which is ignored. However, it is usual to set each 8th bit so that each group of 8
bits has an odd number of bits set to 1. The algorithm is best suited to implementation in hardware,
probably to discourage implementations in software, which tend to be slow by comparison. However,
modern computers are so fast that satisfactory software implementations are readily available.
DES is the most widely used symmetric algorithm in the world, despite claims that the key length is too
short. Ever since DES was first announced, controversy has raged about whether 56 bits is long enough
to guarantee security. The key length argument goes like this. Assuming that the only feasible attack on
DES is to try each key in turn until the right one is found, then 1,000,000 machines each capable of
testing 1,000,000 keys per second would find (on average) one key every 12 hours. Most reasonable
people might find this rather comforting and a good measure of the strength of the algorithm. Those
who consider the exhaustive key-search attack to be a real possibility (and to be fair the technology to
do such a search is becoming a reality) can overcome the problem by using double or triple length keys.
In fact, double length keys have been recommended for the financial industry for many years. Use of
multiple length keys leads us to the Triple-DES algorithm, in which DES is applied three times. If we
consider a triple length key to consist of three 56-bit keys K1, K2, K3 then encryption is as follows:
Encrypt with K1
Decrypt with K2
Encrypt with K3
Decryption is the reverse process:
Decrypt with K3
Encrypt with K2
Decrypt with K1
Setting K3 equal to K1 in these processes gives us a double length key K1, K2.
Setting K1, K2 and K3 all equal to K has the same effect as using a single-length (56-bit key). Thus it is
possible for a system using triple-DES to be compatible with a system using single-DES.

Allenhouse Institute of Technology, Kanpur

28

Department of Computer Science and Engineering

ALGORITHM
1. Ask from user about the word to encrypt
2. pass it on to the DES encrypter
3. encrpt using 64 bit DES algo
4. print the output
Important Questions
1. How many types of DES algos are there?
2. What is the difference between triple DES and normal DES?
Allenhouse Institute of Technology, Kanpur

29

Department of Computer Science and Engineering

3. Which of the following algorithm's RSA or DES will you prefer for 64 bit Encoding? Why.

Allenhouse Institute of Technology, Kanpur

30

You might also like