CNS PDF
CNS PDF
Procedure:
Step 1: Open wireshark and you can see capture button on menu bar. Click on it.
In the drop down menu click on the refresh interfaces.
Step 2: Click on the Network connection that you are working on. Here we used
WiFi and click on the wifi channel.
Step 3:After clicking the WiFi channel we get our database regarding about the
background running websites and it shows the protocols and about it. Here we can
search for the sniffers .
Step 4: Here we see HTTP requests and there we get POST or GET methods used by
other persons we can find out them. Click on it. We get a drop down menu ,there
click on follow button and in that click on the TCP Stream. We can see the following
dialog box.
Step 5: Finally we can see the conversation between source, sniffers and the
destination.
2. understanding of cryptographic algorithms and implementation of same in C
or C++
AIM: To implement the simple substitution technique named Caesar cipher using
Java language.
DESCRIPTION:
To encrypt a message with a Caesar cipher, each letter in the message is
changed using a simple rule: shift by three. Each letter is replaced by the letter
three letters ahead in the alphabet. A becomes D, B becomes E, and so on.
For the last letters, we can think of the
alphabet as a circle and "wrap around". W becomes Z, X becomes A, Y bec mes
B, and Z
becomes C. To change a message back, each letter is replaced by the one three
before it.
ALGORITHM:
import java.io.BufferedReader;
import java.io.IOException; import
java.io.InputStreamReader; import
java.util.Scanner;
public class CeaserCipher {
Stringdecrypted=decrypt(encrypted,
key); System.out.println("\nDecrypted String
is: "
+decrypted); System.out.println("\n");
}
c = c - 26;
}
else if (Character.isLowerCase(c)) {
c = c + (key % 26);
if (c > 'z')
c = c - 26;
}
encrypted += (char) c;
}
return encrypted;
}
c = c + 26;
}
else if (Character.isLowerCase(c)) {
c = c - (key % 26);
if (c < 'a')
OUTPUT:
Enter any string: HelloWorld
Enter key: 5
Encrypted string is: MjqqtBtwqi
Decrypted string is: Hello World
RESULT: Thus the implementation of Caesar cipher had been executed successfully.
DESCRIPTION:
The Playfair cipher starts with creating a key table. The key table is a
5×5 grid of letters that will act as the key for encrypting your plaintext.
Each of the 25 letters must be unique and one letter of the alphabet is
omitted from the table (as there are 25 spots and 26 letters in the
alphabet).
1. If both letters are the same (or only one letter is left), add an "X" after
the first letter
2. If the letters appear on the same row of your table, replace them
with the letters to their immediate right respectively
3. If the letters appear on the same column of your table, replace them
with the letters immediately below respectively
4. If the letters are not on the same row or column, replace them with
the letters on the same row respectively but at the other pair of
corners of the rectangle defined by the original pair.
ALGORITHM:
STEP-1: Read the plain text from the user.
STEP-2: Read the keyword from the user.
STEP-3: Arrange the keyword without duplicates in a 5*5 matrix in the
row order and fill the remaining cells with missed out letters in
alphabetical order. Note that ‘i’ and ‘j’ takes the same cell.
STEP-4: Group the plain text in pairs and match the corresponding
corner letters by forming a rectangular grid.
STEP-5: Display the obtained cipher text.
Program
import java.awt.Point;
class playfairCipher {
private static char[][] charTable;
private static Point[] positions;
private static String prepareText(String s, boolean chgJtoI) {
s = s.toUpperCase().replaceAll("[^A-Z]", "");
return chgJtoI ? s.replace("J", "I") : s.replace("Q", "");
}
private static void createTbl(String key, boolean chgJtoI) {
charTable = new char[5][5];
positions = new Point[26];
String s = prepareText(key + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", chgJtoI);
int len = s.length();
for (int i = 0, k = 0; i < len; i++) {
char c = s.charAt(i);
if (positions[c - 'A'] == null) {
charTable[k / 5][k % 5] = c;
positions[c - 'A'] = new Point(k % 5, k / 5);
k++;
}
}
}
private static String codec(StringBuilder txt, int dir) {
int len = txt.length();
for (int i = 0; i < len; i += 2) {
char a = txt.charAt(i);
char b = txt.charAt(i + 1);
int row1 = positions[a - 'A'].y;
int row2 = positions[b - 'A'].y;
int col1 = positions[a - 'A'].x;
int col2 = positions[b - 'A'].x;
if (row1 == row2) {
col1 = (col1 + dir) % 5;
col2 = (col2 + dir) % 5;
} else if (col1 == col2) {
OUTPUT:
Simulating Playfair Cipher
RESULT:
Thus the program for playfair cipher encryption and decryption algorithm has
been implemented and the output verified successfully.
AIM: To write a Java program to implement the hill cipher substitution technique.
DESCRIPTION:
Each letter is represented by a number modulo 26. Often the simple scheme A = 0,
B
= 1... Z = 25, is used, but this is not an essential feature of the cipher. To encrypt a
message, each block of n letters is multiplied by an invertible n × n matrix,
against modulus 26. To
decrypt the message, each block is multiplied by the inverse of the ma trix
used for
ALGORITHM:
STEP-1: Read the plain text and key from the user.
STEP-2: Split the plain text into groups of length three.
STEP-3: Arrange the keyword in a 3*3 matrix.
STEP-4: Multiply the two matrices to obtain the cipher text of length three.
STEP-5: Combine all these groups to get the complete cipher text.
PROGRAM
import
java.io.*;
import
java.util.*;
RESULT:
Thus the program for hill cipher encryption and decryption algorithm has been
implemented and the output verified successfully.
AIM: To implement the Vigenere Cipher substitution technique using Java.
DESCRIPTION:
To encrypt, a table of alphabets can be used, termed a tabula recta, Vigenère square,
or Vigenère table. It different rows, each
consists of the alphabet
written out 26 times
alphabet shifted cyclically to the left compared to the previous alphabet,
corresponding to the 26 possible Caesar ciphers. At different points in the
encryption process, the cipher uses a different alphabet from one of the rows.
The alphabet used at each point repeating keyword.
Each row starts with a key letter. The remainder of the row holds the letters A to Z.
Although there are 26 key rows shown, you will only use as many keys as there are
unique letters in the key string, here just 5 keys, {L, E, M, O, N}. For successive letters
of the message, we are going to take successive letters of the key string, and
encipher each message
letter using its corresponding key row. Choose the next letter of the key, go al ng
that row to
find the column heading that atches the message character; the letter at the
intersection of
[key-row, msg-col] is the enciphered letter.
ALGORITHM:
STEP-7: The junction character where these two meet forms the cipher character.
STEP-8: Repeat the above steps to generate the entire cipher text.
public class vigenereCipher {
static String encode(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') {
continue;
}
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
static String decode(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') {
continue;
}
res += (char) ((c - key.charAt(j) + 26) % 26 + 'A');
j = ++j % key.length();
}
return res;
}
RESULT:
Thus the program for vigenere cipher encryption and decryption algorithm has
been implemented and the output verified successfully.
AIM: To write a Java program to implement the rail fence transposition technique.
DESCRIPTION:
In the rail fence cipher, the plain text is written downwards and diagonally on
successive "rails" of an imaginary fence, then moving up when we reach the bottom
rail. When we reach the top rail, the message is written downwards again until the
whole plaintext is written out. The message is then read off in rows.
ALGORITHM:
class railFenceCipher {
public static void main(String[] args) throws java.lang.Exception {
railfenceCipherHelper rf = new railfenceCipherHelper();
String msg, enc, dec;
msg = "Anna University, Chennai";
int depth = 2;
enc = rf.encode(msg, depth);
dec = rf.decode(enc, depth);
System.out.println("Simulating Railfence Cipher\n-------------------------");
System.out.println("Input Message : " + msg);
System.out.println("Encrypted Message : " + enc);
System.out.printf("Decrypted Message : " + dec);
}
}
OUTPUT:
Simulating Railfence Cipher
RESULT:
Thus the java program for Rail Fence Transposition Technique has been
implemented and the output verified successfully.
AIM:
To implement a program for encryption and decryption by using row and column
transformation technique.
ALGORITHM:
1. Consider the plain text hello world, and let us apply the simple columnar
transposition technique as shown below
h e l l
o w o r
l d
2. The plain text characters are placed horizontally and the cipher text is created
with vertical format as: holewdlo lr.
3. Now, the receiver has to use the same table to decrypt the cipher text to plain
text.
PROGRAM:
TransCipher.java
import java.util.*;
class TransCipher {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the plain text");
String pl = sc.nextLine();
sc.close();
String s = "";
int start = 0;
for (int i = 0; i < pl.length(); i++) {
if (pl.charAt(i) == ' ') {
s = s + pl.substring(start, i);
start = i + 1;
}
}
s = s + pl.substring(start);
System.out.print(s);
System.out.println();
// end of space deletion
int k = s.length();
int l = 0;
int col = 4;
int row = s.length() / col;
char ch[][] = new char[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (l < k) {
ch[i][j] = s.charAt(l);
l++;
} else {
ch[i][j] = '#';
}
}
}
// arranged in matrix
OUTPUT:
Enter the plain text
Security Lab
SecurityLab
Sreictuy
RESULT:
Thus the java program for Row and Column Transposition Technique has been
implemented and the output verified successfully.
AIM:
DESCRIPTION:
DES is a symmetric encryption system that uses 64-bit blocks, 8 bits of which are used
for parity checks. The key therefore has a "useful" length of 56 bits, which means that
only 56 bits are actually used in the algorithm. The algorithm involves carrying out
combinations, substitutions and permutations between the text to be encrypted and
the key, while making sure the operations can be performed in both directions. The key
is ciphered on 64 bits and made of 16 blocks of 4 bits, generally denoted k1 to k16.
Given that "only" 56 bits are actually used for encrypting, there can be 2 56 different
keys.
The main parts of the algorithm are as follows:
Fractioning of the text into 64-bit blocks
Initial permutation of blocks
Breakdown of the blocks into two parts: left and right, named L and R
Permutation and substitution steps repeated 16 times
Re-joining of the left and right parts then inverse initial permutation
ALGORITHM:
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
try{
System.out.println("Message Encryption Using DES Algorithm\n-------");
KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
SecretKey myDesKey = keygenerator.generateKey();
Cipher desCipher;
desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
byte[] text = "Secret Information ".getBytes();
System.out.println("Message [Byte Format] : " + text);
System.out.println("Message : " + new String(text));
byte[] textEncrypted = desCipher.doFinal(text);
System.out.println("Encrypted Message: " + textEncrypted);
desCipher.init(Cipher.DECRYPT_MODE, myDesKey);
byte[] textDecrypted = desCipher.doFinal(textEncrypted);
System.out.println("Decrypted Message: " + new String(textDecrypted));
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}catch(NoSuchPaddingException e){
e.printStackTrace();
}catch(InvalidKeyException e){
e.printStackTrace();
}catch(IllegalBlockSizeException e){
e.printStackTrace();
}catch(BadPaddingException e){
e.printStackTrace();
}
}
}
OUTPUT:
Message Encryption Using DES Algorithm
RESULT:
Thus the java program for DES Algorithm has been implemented and the output
verified successfully.
AIM:
To use Advanced Encryption Standard (AES) Algorithm for a practical application
like URL Encryption.
ALGORITHM:
1. AES is based on a design principle known as a substitution–permutation.
2. AES does not use a Feistel network like DES, it uses variant of Rijndael.
3. It has a fixed block size of 128 bits, and a key size of 128, 192, or 256 bits.
4. AES operates on a 4 × 4 column-major order array of bytes, termed the state
PROGRAM:
AES.java
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
OUTPUT:
URL Encryption Using AES Algorithm
RESULT:
Thus the java program for AES Algorithm has been implemented for URL Encryption
and the output verified successfully.
byte iv[] =
cipherOut.getIV(); if (iv !=
null) {
fin.close(); cout.close(); }}
OUTPUT:
Initialization Vector of the Cipher:
dI1MXzW97oQ=
STEP-1: Both Alice and Bob shares the same public keys g and p.
STEP-2: Alice selects a random public key a.
STEP-3: Alice computes his secret key A as ga mod p.
STEP-4: Then Alice sends A to Bob.
STEP-5: Similarly Bob also selects a public key b and computes his secret key
as B and sends the same back to Alice.
STEP-6: Now both of them compute their common secret key as the other
one’s secret key power of a mod p.
class DiffieHellman {
public static void main(String args[]) {
int p = 23; /* publicly known (prime number) */
int g = 5; /* publicly known (primitive root) */
int x = 4; /* only Alice knows this secret */
int y = 3; /* only Bob knows this secret */
double aliceSends = (Math.pow(g, x)) % p;
double bobComputes = (Math.pow(aliceSends, y)) % p;
double bobSends = (Math.pow(g, y)) % p;
double aliceComputes = (Math.pow(bobSends, x)) % p;
double sharedSecret = (Math.pow(g, (x * y))) % p;
System.out.println("simulation of Diffie-Hellman key exchange
algorithm\n ");
System.out.println("Alice Sends : " + aliceSends);
System.out.println("Bob Computes : " + bobComputes);
System.out.println("Bob Sends : " + bobSends);
System.out.println("Alice Computes : " + aliceComputes);
System.out.println("Shared Secret : " + sharedSecret);
/* shared secrets should match and equality is transitive */
if ((aliceComputes == sharedSecret) && (aliceComputes == bobComputes))
System.out.println("Success: Shared Secrets Matches! " + sharedSecret);
else
System.out.println("Error: Shared Secrets does not Match");
}
}
OUTPUT:
simulation of Diffie-Hellman key exchange algorithm
RESULT:
Thus the Diffie-Hellman key exchange algorithm has been implemented
using Java Program and the output has been verified successfully
AIM:
To write a Java program to implement the RSA encryption algorithm.
DESCRIPTION:
RSA is an algorithm used by modern computers to encrypt and decrypt
messages. It is an asymmetric cryptographic algorithm. Asymmetric means
that there are two different keys. This is also called public key cryptography,
because one of them can be given to everyone. A basic principle behind RSA is
the observation that it is practical to find three very large positive integers
e, d and n such that with modular exponentiation for all integer m:
(me)d = m (mod n)
The public key is represented by the integers n and e; and, the private key, by
the integer d. m represents the message. RSA involves a public key and a
private key. The public key can be known by everyone and is used for
encrypting messages. The intention is that messages encrypted with the public
key can only be decrypted in a reasonable amount of time using the private
key.
EXAMPLE:
ALGORITHM:
y=
x.nextInt(fiofn.intVal
ue()-1); String z =
Integer.toString(y);
e=new
BigInteger(z); gcd
= fiofn.gcd(e);
intGCD = gcd.intValue();
}
while(y <= 2 ||
intGCD!= 1);
return e;
OUTPUT:
RESULT:
Thus the Java program to implement RSA encryption technique had been
implemented successfully
EXPERIMENT NO.3
Installation:-
1. Download the Open SSL for windows installation package
2. Double click the file.
3. If error occurs, you should install Microsoft visual C++.
4. Double click the installation file and click on next.
5. Click on I accept agreement and next.
6. Leave the default start menu folder and click on next.
7. Leave the windows system directory and click on next.
8. Click on install.
9. Click on finish once the installation completed.
.
HOW DOES SSL WORKS:-
SSL encrypts data communicated across the web to generate a high level of
privacy. Anyone attempting intercept this data will meet a jumbled mess of
character nearly hard to detect.
SSL begins on authentication process known as a handshake b/w two
communicating devices to confirm that both devices are who they say.
STEPS:
1. Generate a private key.
2. Generate a public key and matching the private key.
3. Generate a certificate using signing request.
4. Send the certificate signing request to a certificate authority.
5. Install private log and certificate key for your web, server software.
EXPERIMENT NO.4
4. Using GNU PGP
To encrypt email and files you need to know how to work with PGP keys. Get
up to speed on generating exporting and importing encryption keys with GNU
PGP.
Summary
PORTS/HOSTS
TOPOLOGY
HOST DETAILS
SCANS
10.To Implementation of proxy-based security protocols in c or c++ with
features like confidentiality,
integrity and authentication.
#include <stdio.h>
int main(){
FIL E *fp1, *fp2;
char a;
fp 1= fopen("test.txt", "r");
if (fp1 == NULL)
{ puts ("cannot open test. txt file");
exit(1);
}
fp2 = fopen ("test1, txt", "w");
if (fp2 == NULL){
puts ("Not able to test1 txt file");
fclose (fp1);
exit (1);
a= fget (fp1);
fprintf (fp2, “%c", a+3);
while (a! = EOF){
a= fgetc (fp₁);
fprintf (fp2,”%c", a+3);
printf("test.txt is successfully encrypted and stored to test1. txt");
printf ("n/test.txt can be forwarded to destination");
fclose (fp1);
fclose (fp2);
return 0;
}
test.txt
Deepika
Deepika
Output:-
test. txt is sucessfully encrypted and stored to test1.txt
test1.txt can be forwarded to destination.
test 1. Txt
19hhslnd