#include <stdio.h>
#include <string.h>
int main() {
int i, lp;
char cipher[50], plain[50], key[50];
printf(“nData EncryptionnEnter the plain text: “);
scanf(“%s”, plain);
printf(“nEnter the encryption key: “);
scanf(“%s”, key);
lp = strlen(key);
for(i = 0; plain[i] != ”; i++)
cipher[i] = plain[i] ^ lp;
cipher[i] = ”;
printf(“nThe encrypted text is: %s”, cipher);
for(i = 0; cipher[i] != ”; i++)
plain[i] = cipher[i] ^ lp;
printf(“nDecrypted text is: %s”, plain);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char pwd[20];
char alpha[26] = “abcdefghijklmnopqrstuvwxyz”;
int num[20], i, n, key;
printf(“nEnter the password: “);
scanf(“%s”, pwd);
n = strlen(pwd);
for(i = 0; i < n; i++)
num[i] = toascii(tolower(pwd[i])) – ‘a’;
printf(“nEnter the key: “);
scanf(“%d”, &key);
for(i = 0; i < n; i++)
num[i] = (num[i] + key) % 26;
for(i = 0; i < n; i++)
pwd[i] = alpha[num[i]];
printf(“nThe key is: %d”, key);
printf(“nEncrypted text is: %s”, pwd);
for(i = 0; i < n; i++) {
num[i] = (num[i] – key) % 26;
if(num[i] < 0) num[i] += 26;
pwd[i] = alpha[num[i]];
}
printf(“nDecrypted text is: %s”, pwd);
return 0;
}
set ns [new Simulator]; set nf [open out.nam w]; $ns namtrace-all $nf; proc finish {} {global ns nf; $ns flush-trace; close $nf; exec nam out.nam &; exit 0}; set n0 [$ns node]; set n1 [$ns node]; set n2 [$ns node]; set n3 [$ns node]; set n4 [$ns node]; set n5 [$ns node]; $ns duplex-link $n0 $n1 1Mb 10ms DropTail; $ns duplex-link $n1 $n2 1Mb 10ms DropTail; $ns duplex-link $n2 $n3 1Mb 10ms DropTail; $ns duplex-link $n3 $n4 1Mb 10ms DropTail; $ns duplex-link $n4 $n5 1Mb 10ms DropTail; $ns duplex-link $n5 $n0 1Mb 10ms DropTail; set tcp0 [new Agent/TCP]; $tcp0 set class_ 1; $ns attach-agent $n0 $tcp0; set sink0 [new Agent/TCPSink]; $ns attach-agent $n3 $sink0; $ns connect $tcp0 $sink0; set cbr0 [new Application/Traffic/CBR]; $cbr0 set packetSize_ 500; $cbr0 set interval_ 0.01; $cbr0 attach-agent $tcp0; $ns at 0.5 “$cbr0 start”; $ns at 4.5 “$cbr0 stop”; $ns at 5.0 “finish”; $ns run
set ns [new Simulator]; $ns color 1 Blue; $ns color 2 Red; set nf [open out.nam w]; $ns namtrace-all $nf; set f0 [open out.tr w]; $ns trace-all $f0; proc finish {} {global ns nf f0; $ns flush-trace; close $f0; close $nf; exec nam out.nam &; exit 0}; set n0 [$ns node]; set n1 [$ns node]; set n2 [$ns node]; set n3 [$ns node]; $ns duplex-link $n0 $n2 2Mb 10ms DropTail; $ns duplex-link $n1 $n2 2Mb 10ms DropTail; $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail; $ns queue-limit $n2 $n3 10; $ns duplex-link-op $n0 $n2 orient right-down; $ns duplex-link-op $n1 $n2 orient right-up; $ns duplex-link-op $n2 $n3 orient right; $ns duplex-link-op $n2 $n3 queuePos 0.5; set tcp [new Agent/TCP]; $tcp set class_ 2; $ns attach-agent $n0 $tcp; set sink [new Agent/TCPSink]; $ns attach-agent $n3 $sink; $ns connect $tcp $sink; $tcp set fid_ 1; set ftp [new Application/FTP]; $ftp attach-agent $tcp; $ftp set type_ FTP; set udp [new Agent/UDP]; $ns attach-agent $n1 $udp; set null [new Agent/Null]; $ns attach-agent $n3 $null; $ns connect $udp $null; $udp set fid_ 2; set cbr [new Application/Traffic/CBR]; $cbr attach-agent $udp; $cbr set type_ CBR; $cbr set packet_size_ 1000; $cbr set rate_ 1mb; $cbr set random_ false; $ns at 0.1 “$cbr start”; $ns at 1.0 “$ftp start”; $ns at 4.0 “$ftp stop”; $ns at 4.5 “$cbr stop”; $ns at 4.5 “$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink”; $ns at 5.0 “finish”; puts “CBR packet size = [$cbr set packet_size_]”; puts “CBR interval = [$cbr set interval_]”; $ns run
set ns [new Simulator]; $ns rtproto DV; $ns macType Mac/Sat/UnslottedAloha; set nf [open aloha.nam w]; $ns namtrace-all $nf; set f0 [open aloha.tr w]; $ns trace-all $f0; proc finish {} {global ns nf f0; $ns flush-trace; close $f0; close $nf; exec nam aloha.nam &; exit 0}; set n0 [$ns node]; set n1 [$ns node]; set n2 [$ns node]; set n3 [$ns node]; set n4 [$ns node]; set n5 [$ns node]; $ns duplex-link $n0 $n4 1Mb 50ms DropTail; $ns duplex-link $n1 $n4 1Mb 50ms DropTail; $ns duplex-link $n2 $n5 1Mb 1ms DropTail; $ns duplex-link $n3 $n5 1Mb 1ms DropTail; $ns duplex-link $n4 $n5 1Mb 50ms DropTail; $ns duplex-link $n2 $n3 1Mb 50ms DropTail; $ns duplex-link-op $n4 $n5 queuePos 0.5; set udp0 [new Agent/UDP]; $ns attach-agent $n0 $udp0; set cbr0 [new Application/Traffic/CBR]; $cbr0 set packetSize_ 500; $cbr0 set interval_ 0.005; $cbr0 attach-agent $udp0; set null0 [new Agent/Null]; $ns attach-agent $n2 $null0; $ns connect $udp0 $null0; $ns at 0.5 “$cbr0 start”; $ns rtmodel-at 1.0 down $n5 $n2; $ns rtmodel-at 2.0 up $n5 $n2; $ns at 4.5 “$cbr0 stop”; $ns at 5.0 “finish”; $ns run
set ns [new Simulator]; set n0 [$ns node]; set n1 [$ns node]; $ns at 0.0 “$n0 label Sender”; $ns at 0.0 “$n1 label Receiver”; set nf [open stop.nam w]; $ns namtrace-all $nf; set f [open stop.tr w]; $ns trace-all $f; $ns duplex-link $n0 $n1 0.2Mb 200ms DropTail; $ns duplex-link-op $n0 $n1 orient right; $ns queue-limit $n0 $n1 10; Agent/TCP set nam_tracevar_ true; set tcp [new Agent/TCP]; $tcp set window_ 1; $tcp set maxcwnd_ 1; $ns attach-agent $n0 $tcp; set sink [new Agent/TCPSink]; $ns attach-agent $n1 $sink; $ns connect $tcp $sink; set ftp [new Application/FTP]; $ftp attach-agent $tcp; $ns add-agent-trace $tcp tcp; $ns monitor-agent-trace $tcp; $tcp tracevar cwnd_; $ns at 0.1 “$ftp start”; $ns at 3.0 “$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink”; $ns at 3.5 “finish”; $ns at 0.0 “$ns trace-annotate “Stop and Wait with normal operation””; $ns at 0.05 “$ns trace-annotate “FTP starts at 0.1″”; $ns at 0.11 “$ns trace-annotate “Send Packet_0″”; $ns at 0.35 “$ns trace-annotate “Receive Ack_0″”; $ns at 0.56 “$ns trace-annotate “Send Packet_1″”; $ns at 0.79 “$ns trace-annotate “Receive Ack_1″”; $ns at 0.99 “$ns trace-annotate “Send Packet_2″”; $ns at 1.23 “$ns trace-annotate “Receive Ack_2 “”; $ns at 1.43 “$ns trace-annotate “Send Packet_3″”; $ns at 1.67 “$ns trace-annotate “Receive Ack_3″”; $ns at 1.88 “$ns trace-annotate “Send Packet_4″”; $ns at 2.11 “$ns trace-annotate “Receive Ack_4″”; $ns at 2.32 “$ns trace-annotate “Send Packet_5″”; $ns at 2.55 “$ns trace-annotate “Receive Ack_5 “”; $ns at 2.75 “$ns trace-annotate “Send Packet_6″”; $ns at 2.99 “$ns trace-annotate “Receive Ack_6″”; $ns at 3.1 “$ns trace-annotate “FTP stops””; proc finish {} {global ns nf; $ns flush-trace; close $nf; puts “running nam…”; exec nam stop.nam &; exit 0}; $ns run