Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Network & Cyber Security (639402)

Practical:3 To perform Various encryption-decryption techniques with


cryptool.
Caesar Cipher:-
Encryption:

Dilip Vikani (215690694041) Page 1


Network & Cyber Security (639402)

Playfair Cipher:-

Dilip Vikani (215690694041) Page 2


Network & Cyber Security (639402)

RSA Algorithm:-

Dilip Vikani (215690694041) Page 3


Network & Cyber Security (639402)

Dilip Vikani (215690694041) Page 4


Network & Cyber Security (639402)

AES Algorithm:-

Dilip Vikani (215690694041) Page 5


Network & Cyber Security (639402)

DES Algorithm:-

Dilip Vikani (215690694041) Page 6


Network & Cyber Security (639402)

Practical:4 To Implement Caesar cipher encryption-decryption & playfair


cipher encryption-decryption.
Caesar Cipher Encryption & Decryption
Input:-
#include<stdio.h>
char text[100],ch;
int i, key;
void encryptionCaesarCipher()
{
for(i = 0; text[i]!= '\0'; ++i)
{
ch = text[i];
if(ch >= 'a' && ch <= 'z')
{
ch = ch + key;
if(ch > 'zs')
ch = ch - 'z' + 'a' - 1;
text[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z')
{
ch = ch + key;
if(ch > 'Z')
ch = ch - 'Z' + 'A' - 1;
text[i] = ch;
}
}
printf("Encrypted text: %s\n\n", text);
}
void decryptionCaesarCipher()
{
for(i = 0; text[i] != '\0'; ++i)
{
ch = text[i];
if(ch >= 'a' && ch <= 'z')
{
ch = ch - key;
if(ch < 'a')
ch = ch + 'z' - 'a' + 1;
text[i] = ch;

Dilip Vikani (215690694041) Page 7


Network & Cyber Security (639402)

}
else if(ch >= 'A' && ch <= 'Z')
{
ch = ch - key;
if(ch < 'A')
ch = ch + 'Z' - 'A' + 1;
text[i] = ch;
}
}
printf("Decrypted text: %s", text);
}
int main()
{
int choice;
printf("\n##### MENU #####\n");
printf("Enter 1 To Encryption of Caesar Cipher \n");
printf("Enter 2 To Decryption of Caesar Cipher \n");
printf("Enter 0 To Exit\n");
while(1)
{
printf("\n\nEnter The Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter a text to Encryption : ");
scanf("%s", text);
printf("Enter key : ");
scanf("%d", &key);
encryptionCaesarCipher();
break;
case 2:
printf("\nEnter a text to Decryption : ");
scanf("%s", text);
printf("Enter key : ");
scanf("%d", &key);
decryptionCaesarCipher();
break;
case 0:
return 0;
default:
printf("Please Enter Valid Choice\n");

Dilip Vikani (215690694041) Page 8


Network & Cyber Security (639402)

break;
}
}
return 0;
}
Output:-

Dilip Vikani (215690694041) Page 9


Network & Cyber Security (639402)

• Playfair Cipher Encryption


#include <stdio.h>
#include <stdlib.h>
#include <string.h> #define SIZE 30
// Function to convert the string to lowercase void toLowerCase(char plain[], int ps)
{
int i;
for (i = 0; i < ps; i++) {
if (plain[i] > 64 && plain[i] < 91) plain[i] += 32;
}
}

// Function to remove all spaces in a string int removeSpaces(char* plain, int ps)
{
int i, count = 0;
for (i = 0; i < ps; i++)
if (plain[i] != ' ')
plain[count++] = plain[i]; plain[count] = '\0';
return count;
}

// Function to generate the 5x5 key square


void generateKeyTable(char key[], int ks, char keyT[5][5])
{
int i, j, k, flag = 0, *dicty;

// a 26 character hashmap
// to store count of the alphabet dicty = (int*)calloc(26, sizeof(int)); for (i = 0; i < ks; i++) {
if (key[i] != 'j')
dicty[key[i] - 97] = 2;
}

dicty['j' - 97] = 1;

i = 0;
j = 0;
for (k = 0; k < ks; k++) {
if (dicty[key[k] - 97] == 2) {
dicty[key[k] - 97] -= 1;
keyT[i][j] = key[k]; j++;
if (j == 5) {
i++; j = 0;

Dilip Vikani (215690694041) Page 10


Network & Cyber Security (639402)

}
}
}

for (k = 0; k < 26; k++) { if (dicty[k] == 0) {


keyT[i][j] = (char)(k + 97); j++;
if (j == 5) {
i++; j = 0;
}
}
}
}

// Function to search for the characters of a digraph


// in the key square and return their position
void search(char keyT[5][5], char a, char b, int arr[])
{
int i, j;

if (a == 'j')
a = 'i'; else if (b == 'j')
b = 'i';

for (i = 0; i < 5; i++) {

for (j = 0; j < 5; j++) {

if (keyT[i][j] == a) {
arr[0] = i;
arr[1] = j;
}
else if (keyT[i][j] == b) { arr[2] = i;
arr[3] = j;
}
}
}
}

// Function to find the modulus with 5 int mod5(int a) { return (a % 5); }

// Function to make the plain text length to be even int prepare(char str[], int ptrs)
{

Dilip Vikani (215690694041) Page 11


Network & Cyber Security (639402)

if (ptrs % 2 != 0) {
str[ptrs++] = 'z';
str[ptrs] = '\0';
}
return ptrs;
}

// Function for performing the encryption


void encrypt(char str[], char keyT[5][5], int ps)
{
int i, a[4];

for (i = 0; i < ps; i += 2) {


search(keyT, str[i], str[i + 1], a); if (a[0] == a[2]) {
str[i] = keyT[a[0]][mod5(a[1] + 1)];
str[i + 1] = keyT[a[0]][mod5(a[3] + 1)];
}
else if (a[1] == a[3]) {
str[i] = keyT[mod5(a[0] + 1)][a[1]];
str[i + 1] = keyT[mod5(a[2] + 1)][a[1]];

}
else {

}
}
}

str[i] = keyT[a[0]][a[3]];
str[i + 1] = keyT[a[2]][a[1]];

// Function to encrypt using Playfair Cipher


void encryptByPlayfairCipher(char str[], char key[])
{
char ps, ks, keyT[5][5];

// Key
ks = strlen(key);
ks = removeSpaces(key, ks); toLowerCase(key, ks);
// Plaintext
ps = strlen(str); toLowerCase(str, ps);

Dilip Vikani (215690694041) Page 12


Network & Cyber Security (639402)

ps = removeSpaces(str, ps); ps = prepare(str, ps);


generateKeyTable(key, ks, keyT);

encrypt(str, keyT, ps);


}

// Driver code int main()


{
char str[SIZE], key[SIZE]; clrscr();
// Key to be encrypted
printf("\n Key text: ");
gets(key);
printf(" Plain Text: ");
gets(str);
printf("\n Cipher text: %s", str);
return 0;
}
Output:

Dilip Vikani (215690694041) Page 13


Network & Cyber Security (639402)

• Playfair Cipher Decryption


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 30

// Convert all the characters


// of a string to lowercase
void toLowerCase(char plain[], int ps)
{
int i;
for (i = 0; i < ps; i++) {
if (plain[i] > 64 && plain[i] < 91) plain[i] += 32;
}
}

// Remove all spaces in a string


// can be extended to remove punctuation int removeSpaces(char* plain, int ps)
{
int i, count = 0;
for (i = 0; i < ps; i++)
if (plain[i] != ' ')
plain[count++] = plain[i]; plain[count] = '\0';
return count;
}

// generates the 5x5 key square


void generateKeyTable(char key[], int ks, char keyT[5][5])
{
int i, j, k, flag = 0, *dicty;

// a 26 character hashmap
// to store count of the alphabet dicty = (int*)calloc(26, sizeof(int));

Dilip Vikani (215690694041) Page 14


Network & Cyber Security (639402)

for (i = 0; i < ks; i++) {


if (key[i] != 'j')
dicty[key[i] - 97] = 2;
}
dicty['j' - 97] = 1;

i = 0;
j = 0;
for (k = 0; k < ks; k++) {
if (dicty[key[k] - 97] == 2) {
dicty[key[k] - 97] -= 1;
keyT[i][j] = key[k]; j++;
if (j == 5) {
i++; j = 0;
}
}
}
for (k = 0; k < 26; k++) { if (dicty[k] == 0) {
keyT[i][j] = (char)(k + 97); j++;
if (j == 5) {
i++; j = 0;
}
}
}

// Search for the characters of a digraph


// in the key square and return their position
void search(char keyT[5][5], char a, char b, int arr[])
{
int i, j;

if (a == 'j')
a = 'i'; else if (b == 'j')
b = 'i';

for (i = 0; i < 5; i++) {

Dilip Vikani (215690694041) Page 15


Network & Cyber Security (639402)

for (j = 0; j < 5; j++) {


if (keyT[i][j] == a) {
arr[0] = i;
arr[1] = j;
}
else if (keyT[i][j] == b) { arr[2] = i;
arr[3] = j;
}
}
}
}

// Function to find the modulus with 5


int mod5(int a){
if (a < 0)
a += 5;
return (a % 5);
}

// Function to decrypt
void decrypt(char str[], char keyT[5][5], int ps)
{
int i, a[4];
for (i = 0; i < ps; i += 2) {
search(keyT, str[i], str[i + 1], a); if (a[0] == a[2]) {
str[i] = keyT[a[0]][mod5(a[1] - 1)];
str[i + 1] = keyT[a[0]][mod5(a[3] - 1)];
}
else if (a[1] == a[3]) {
str[i] = keyT[mod5(a[0] - 1)][a[1]];
str[i + 1] = keyT[mod5(a[2] - 1)][a[1]];

}
else {
str[i] = keyT[a[0]][a[3]];
str[i + 1] = keyT[a[2]][a[1]];

Dilip Vikani (215690694041) Page 16


Network & Cyber Security (639402)

}
// Function to call decrypt
void decryptByPlayfairCipher(char str[], char key[])
{
char ps, ks, keyT[5][5];

// Key
ks = strlen(key);
ks = removeSpaces(key, ks); toLowerCase(key, ks);

// ciphertext
ps = strlen(str); toLowerCase(str, ps);
ps = removeSpaces(str, ps); generateKeyTable(key, ks, keyT);
decrypt(str, keyT, ps);
}
// Driver code int main()
char str[SIZE], key[SIZE]; clrscr();
// Key to be encrypted
printf("\n key text: ");
gets(key);
// Ciphertext to be decrypted
printf("\n Cipher text: %s", str);
// encrypt using Playfair Cipher decryptByPlayfairCipher(str, key);
printf("\n Deciphered text: %s", str);
return 0;
}
Output:

Dilip Vikani (215690694041) Page 17


Network & Cyber Security (639402)

Practical:6.1. To Perform Open Source Intelligence(OSINT) about any specific


domain. (WHOIS , DNS ,Lookup &other Tools)- A passive Information
Gathering Technique.

WHOIS:-
WHOIS allows you to look up the name and contact information of whoever operates any
website's generic domain name. As part of the registration process, you must provide your
registrar with accurate and reliable contact details and promptly correct and update these
details as necessary.

Dilip Vikani (215690694041) Page 18


Network & Cyber Security (639402)

IPConfig:-
The ipconfig command is used to display information about your network configuration and
refresh DHCP and DNS Settings. By default, the ipconfig command displays your IP Address,
Subnet Mask, and default gateway. But with correct parameters, you can get a lot more
information out of it

Dilip Vikani (215690694041) Page 19


Network & Cyber Security (639402)

NsLookup:-
nslookup is a network administration command-line tool available for many computer
operating systems. Find the IP address of a host. Find the domain name of an IP address.
Find mail servers for a domain. It is used for querying the Domain Name System (DNS) to
obtain domain name or IP address mapping information The main use of nslookup is for
troubleshooting DNS related problems. Nslookup can be use in interactive and non-
interactive mode. To use in interactive mode type nslookup at the command line and hit
return.

Dilip Vikani (215690694041) Page 20


Network & Cyber Security (639402)

Practical:6.2.To Study the use of Network reconnaissance tools like ping,


traceroute ,nslookup to gather information about networks and domain
registrars.

Ping:-
The ping command sends packets of data to a specific IP address on a network, and then
lets you know how long it took to transmit that data and get a response. It’s a handy tool
that you can use to quickly test various points of your network. ping is the primary TCP/IP
command used to troubleshoot connectivity, reachability, and name resolution. Used
without parameters, this command displays Help content. You can also use this command to
test both the computer name and the IP address of the computer

Dilip Vikani (215690694041) Page 21


Network & Cyber Security (639402)

Here, some are the option which we can use with ping
1. -h:-

Dilip Vikani (215690694041) Page 22


Network & Cyber Security (639402)

2. -c:-We can define the number of packets to send to the server/host by using -c option.

3. -t:-

Dilip Vikani (215690694041) Page 23


Network & Cyber Security (639402)

Traceroute:-
The UNIX/Linux traceroute command (tracert on a Windows computer) identifies the route
a packet takes between your computer and the destination computer specified in the
command. By default, traceroute sends three packets of data to test each 'hop' (when a
packet is passed between routers it is called a 'hop'). The Windows Tracert tool determines
the route to a destination by sendingICMP packets to the destination.

Dilip Vikani (215690694041) Page 24


Network & Cyber Security (639402)

Practical:7 To perform port scanning using various methods & techniques


provided by Nmap or Zenmap.
7.1 Scanning Techniques
7.1.1 TCP SYN SCAN

7.2.2 TCP CONNECT SCAN

7.2.3 UDP SCAN

7.2.4 SCTP INIT SCAN

Dilip Vikani (215690694041) Page 25


Network & Cyber Security (639402)
7.2.5 TCP NULL Scan

7.2.6 Xmas Scan

Dilip Vikani (215690694041) Page 26


Network & Cyber Security (639402)

Practical:9.1.To Implement a packet capturing tool(Wireshark) and Capture


the real time traffic.

TCP:-

Dilip Vikani (215690694041) Page 27


Network & Cyber Security (639402)

Practical:9.2.To Study & analyse the captured packets for different protocols
& search queries using Wireshark.

Dilip Vikani (215690694041) Page 28


Network & Cyber Security (639402)

UDP:-

Dilip Vikani (215690694041) Page 29


Network & Cyber Security (639402)

Melissa Virus
A few decades ago, computer viruses—and public awareness of the tricks used to unleash them—
were still relatively new notions to many Americans.

In late March 1999, a programmer named David Lee Smith hijacked an America Online (AOL)
account and used it to post a file on an Internet newsgroup named “alt.sex.” The posting promised
dozens of free passwords to fee-based websites with adult content. When users took the bait,
downloading the document and then opening it with Microsoft Word, a virus was unleashed on their
computers.
The Melissa virus, reportedly named by Smith for a stripper in Florida, started by taking over victims’
Microsoft Word program. It then used a macro to hijack their Microsoft Outlook email system and
send messages to the first 50 addresses in their mailing lists. Those messages, in turn, tempted
recipients to open a virus-laden attachment by giving it such names as “sexxxy.jpg” or “naked wife”
or by deceitfully asserting, “Here is the document you requested ... don’t show anyone else ;-).”
With the help of some devious social engineering, the virus operated like a sinister, automated chain
letter.
The virus was not intended to steal money or information, but it wreaked plenty of havoc
nonetheless. Email servers at more than 300 corporations and government agencies worldwide
became overloaded, and some had to be shut down entirely, including at Microsoft. Approximately
one million email accounts were disrupted, and Internet traffic in some locations slowed to a crawl.
Within a few days, cybersecurity experts had mostly contained the spread of the virus and restored
the functionality of their networks, although it took some time to remove the infections entirely.
Along with its investigative role, the FBI sent out warnings about the virus and its effects, helping to
alert the public and reduce the destructive impacts of the attack. Still, the collective damage was
enormous: an estimated $80 million for the cleanup and repair of affected computer systems.
Finding the culprit didn’t take long, thanks to a tip from a representative of AOL and nearly seamless
cooperation between the FBI, New Jersey law enforcement, and other partners. Authorities traced
the electronic fingerprints of the virus to Smith, who was arrested in northeastern New Jersey on
April 1, 1999. Smith pleaded guilty in December 1999, and in May 2002, he was sentenced to 20
months in federal prison and fined $5,000. He also agreed to cooperate with federal and state
authorities.
The Melissa virus, considered the fastest spreading infection at the time, was a rude awakening to
the dark side of the web for many Americans. Awareness of the danger of opening unsolicited email
attachments began to grow, along with the reality of online viruses and the damage they can do.
Like the Morris worm just over a decade earlier, the Melissa virus was a double-edged sword,
leading to enhancements in online security while serving as inspiration for a wave of even more
costly and potent cyberattacks to come.
For the FBI and its colleagues, the virus was a warning sign of a major germinating threat and of the
need to quickly ramp up its cyber capabilities and partnerships.
Fittingly, a few months after Smith was sentenced, the Bureau put in place its new national Cyber
Division focused exclusively on online crimes, with resources and programs devoted to protecting
America’s electronic networks from harm. Today, with nearly everything in our society connected to
the Internet, that cyber mission is more crucial than ever.

Dilip Vikani (215690694041) Page 30

You might also like