Program 7
7. Implement data encryption and data decryption.
AIM: Implement Data Eneryption and Data Decryption.
Software Required: PC loaded with GCC/Turbo C
‘Theory
Data encryption standard was widely adopted by the industry in security products.
Plain text is encrypted in blocks of 64
its yielding 64 bits of cipher text. The
algorithm which is parameterized by a 56 bit key has 19 dist
stage
transposition, The remaining stages are functionally identical but are parameterized
stages. The first
‘a key independent transposition and the last stage is exactly inverse of the
by different functions of the key. The algorithm has been designed to allow
decryption to be done with the same key as encryption
Algorithm:
Begin
Stepl: Initialize as int ichalp;
Step2s Initialize as char
cipher{50},plain{50]; Step3: Initialize as
char key{ 50}:
Step4: while(1) repeat steps(4-36)
StepS: write "\n----MENU =n"
Step6: write
Step?: write ("WnlnEnter your choice:”
Data Eneryption\tn\n2:Data Deeryption\\n\n3:Exi
Stop8: read"Zid" &ech
Step9: stament switch(ch) repeat steps(9-35)
cease I:
stepl0: read "Data Eneryption"
step! read ("WnEnter the plain text"
step!2: fflush(stdin)step13 : gets(plain)
step!4: write "Enter the encryption key!"
stepI5: gets(key)
step16: Ip=strlen(key)
step17: Initialize i-0
step18: repeat until plain[il!=\0"
step19: inevement i
step20: initialize
cipher{i}=plainti)*Ip
step2I: initialize cipherfi]=\0';
step22: write "WwThe encrypted text is:"
step23: puts(cipher)
step24: break
‘ease 2:
step25: write"\nData decryption”
‘tep26: Initialize i=0
step27: repeat until plain{i}!=\0"
step28: increment i
step29: initialize
plain[i}cipherti}*Ip
step30:write"nDecrypted text
iss" step32: puts(plain)
step33:brea
k ease 3:
step34:exin
dy
step35: end switch stmt
step36: end while(1)stmt EndSource Code:
#include
#include
#includesstring.h>
void main()
{
int ichalp;
char eipher{50} plain{50};
char key[50];,
while(l)
"wnl:data encryption\t\n\n2:data decryption\t\n\n3:exit");
"w\nenter your choice:");
scanfi"Sed" Sch);
switeh(ch)
{
cease I:printf("\ndata encryption”);
printf("\n enter the plain text:");
Higets(plain);
seanf("ss" &plain);
printi("\nenter the encryption key:");
Mgets(key):
scanft"%s",dekey);
printf("\n the encrypted text is:")
case 2:printf("\n data decryotion”);
forti=0cipher
plain[i}=cipherti}“Ip:
"indecrypted text is:");
puts(plain);
break:
case 3:exit(O):
i
}ourPuT
Inout
J:data encryption
2:data decryption
Seexit
enter your choicest
data encryption
center the plain texthello
center the encryption key:123
the encrypted text is:kfoo!
Iedata eneryption
2edata decryption
3eexit
center your cho
data deeryotion
decrypted text isshello
Iedata eneryption
2edata decryption
exit
center your choice: 3
ResuProgram-8
8, Write a program for congestion control using Leaky bucket algorithm,
AIM: Write a program for congestion control using Leaky bucket algorithm.
Software Required: PC loaded with GCC/Turbo C .
‘Theory:
‘The congesting control algorithms are basically divided into two groups: open loop
and closed loop. Open loop solutions attempt to solve the problem by good design, in
essence, to make sure it does not occur inthe first place. Once the system is up and running,
midcourse corrections are not made. Open loop algorithms are further divided into ones that
act at source versus ones that act at the destination
In contrast, closed loop solutions are based on the concept of a feedback loop if there is any
congestion. Closed loop algorithms are also divided into two sub categories: explicit
feedback and implicit feedback. In explicit feedback algorithms, packets are sent back from
the point of congestion to warn the source. In implicit algorithm, the source deduces the
existence of congestion by making local observation, such as the time needed for
acknowledgment to come back.
‘The presence of congestion means that the load is (temporarily) greater than the resources (in
part of the system) can handle. For subnets that use virtual circuits internally, these methods
can be used at the network layer.
Another open loop method to help manage congestion is forcing the packet to be transmitted
at a more predictable rate. This approach to congestion management is widely used in ATM.
networks and is called traffic shaping,
‘The other method is the leaky bucket algorithm. Each host is connected to the network by an
interface containing a leaky bucket, that is, a finite internal queue. Ifa packet arrives at the
{queue when itis Full, the packet is discarded. In other words, if one or more process are
already queued, the new packet is unceremoniously discarded. This arrangement can be built
into the hardware interface or simulate d by the host operating system. In fact itis nothing
other than a single server queuing system with constant service time.
‘The host is allowed to put one packet per clock tick onto the network. This mechanism tums
fan uneven flow of packet from the user process inside the host into an even flow of packet
nto the network, smoothing out bursts and greatly reducing the chances of congestion.
Algorithm:
Start
Set the bucket size or the buffer size.
Set the output rate.
‘Transmit the packets such that there is no overflow.
Repeat the process of transmission until all packets are transmitted. (Reject packets‘where its size is greater than the bucket size)
6. Stop
Source code:
ineludesstdio.h>
int main)
{
int incoming, outgoing, buck_size, n, store = 0;
printf("Enter bucket size, outgoing rate and no of inputs:
scanf (Sed ‘éd 9d", &ebuck_size, &outgoing, 8m);
while (a
{
printf("Enter the incoming packet size
seanf(%d", &incoming):
printf"Incoming packet size Sdn
if (incoming <= (buck_size - store)
{
Store += incoming:
printf("Bucket buffer size %ed out of edi", store, buck size):
} else
{
printf( "Dropped “ed no of packets\n", incoming - (buck_size - store));
printf("Bucket buffer size Sed out of “edn, store, buck size):
store = buck size;
)
store = store - outgoing:
printf("After outgoing %d packets left out of Sd in buffer\n’, store, buck size):
0
/* OUTPUT
gedit program8.c
gee programs.c
ZaLout
Enter bucket size, outgoing rate and no of inputs: 30 20 3
Enter the incoming packet size ; 20
Incoming packet size 20
Bucket butfer size 20 out of 30
fier outgoing 0 packets eft out of 30 in buffer
Enter the incoming packet size : 30
Incoming packet size 30
Bucket buffer size 30 out of 30
After outgoing 10 packets left out of 30 in bufferEnter the incoming packer size : 40
Incoming packet size 40,
Dropped 20 no of packets
Bucket buffer size 10 out of 30,
After outgoing 10 packets left out of 30 in buffer
”
Result:Progeam-9
9. Write a program for frame sorting technique used in buffers.
AIM: Write a program for frame sorting technique used in buffers.
Software Required: PC loaded with GCC/Turbo C .
‘Theory:
A frame isa digital: dat
transmission unit in computer networking and
telecommunication. A frame typically includes frame synchronization features consisting of a
sequence of bits or symbols that indicate to the receiver the beginning and end of the payload
data within the stream of symbols orbits it receives. I'a receiver is connected to the system in
the middle of a frame transmission, it ignores the data until it detects a new frame
synchronization sequence.
Algorithm:
Source Code:
#include
includesstring.h>
‘define FRAM_TXT SIZ 3
‘define MAX_NOF_FRAM. 127
char str[FRAM_TXT_SIZ*MAX_NOF_FRAMI;
struct frame structure maintained to hold frames,
{
char text{FRAM_TXT_SIZ};
int seq_no;
)
irl MAX_NOF_FRAM], shut_ary[MAX_NOF_FRAM];
int assign_seq_no() function which spits message
{
Int k=0,i,j; Minto frames and assigns sequence no
forti=0; i < strlem(str); k++)
{
Frfk}.seq_no = ks
for(j=0; | shuf_arylj+1].seq_no)
{
hold = shu aryfj
44) // search for frames in sequence
snuf_ary{j] = shuf_ary(+1s
shut_aryl+1] = hold;
fa
}
}
}
int main)
{
int no_frame
printf("Enter the message:
gets(ste):
1no_frames = assign_seq_n0();
shuffle(ne_frames);sort(ne_frames);
print{("\n\nAFTER SORTINGWn")
forti=D:isno_framesti++)
printf("*s"shuf_aryfil. text;
)
pourPuT
gedit program9.c
gee program9.c
aout
Enter the message: Weleome To Sreyas Insitute of engineering and Technology
After assigning sequence numbers
O:Wel I:com 2:0 T 3:0 § 4itey S:as. 6:Tns 7:tt Bute 9: of 10: en IL:gin L2:eer 13:ing 14: an
15:d T I6:ech 17:nol 18:0gy
AFTER SHUFFLING:
eT 15d T 3:0§ 10: en S:ute I-gin 7st I:com 9: of IT:nol S:as 12:cer G:lns d:rey 14: an
1 :ing L6:ech O:Wel L8:0gy
AFTER SORTING
‘Welcome To Sreyas Institute of engineering and Technology
”
Result: