CNS Lab Manual
CNS Lab Manual
CNS Lab Manual
Accredited by NAAC
IV B. TECH I SEMESTER
Accredited by NAAC
Accredited by NAAC
Engineeringknowledge:Applytheknowledgeofmathematics,science,engineering Fundamentals
PO1
andanengineeringspecializationtothesolutionofcomplexengineeringproblems.
Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
PO2 problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems anddesign
system components or processes that meet the specified needs with appropriate consideration
PO3
for the public health and safety, and the cultural, societal, and environmental
considerations.
Conduct investigations of complex problems: Use research-based knowledge and research
PO4 methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
PO5 engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to assesssocietal,
PO6 health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
Environment and sustainability: Understand the impact of the professional engineering Solutions in
PO7 societal and environmental contexts, and demonstrate the knowledge of, and needfor sustainable
development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities andnorms
PO8
of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or leaderIn diverse
PO9
teams, and in multi-disciplinary settings.
Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write
PO10
effective reports and design documentation, make effective presentations, and give and receiveclear
instructions.
Project management and finance: Demonstrate knowledge and understanding of the Engineering
PO11 and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in
PO12
independent and life-long learning in the broadest context of technological change.
Problem Solving Skills – Graduate will be able to apply computational techniques and software
PSO1
principles to solve complex engineering problems pertaining to software engineering.
Professional Skills – Graduate will be able to think critically, communicate effectively, and
PSO2
collaborate in teams through participation in co and extra-curricular activities.
Successful Career – Graduates will possess a solid foundation in computer science and
PSO3 engineering that will enable them to grow in their profession and pursue lifelong learning
through post-graduation and professional development.
COMPUTERSCIENCE&ENGINEERING
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
INDEX
S.NO. TOPIC PAGE NUMBER
WriteaJavaprogramtoperformencryptionanddecryption
usingthefollowingalgorithms:
3 3-9
a) CeaserCipher
b) SubstitutionCipher
c) HillCipher
4 WriteaJavaprogramtoimplementtheDESalgorithmlogic 10-12
WriteaC/JAVAprogramtoimplementtheBlowFishalgorithmlogic
5 13-14
WriteaC/JAVAprogramtoimplementtheRijndaelalgorithmlogic.
6 15
UsingJavaCryptography,encryptthetext“Helloworld”usingBlowFish.Createyourow
7 nkeyusingJavakeytool. 17-18
8 WriteaJavaprogramtoimplementRSAAlgoithm 19
ImplementtheDiffie-HellmanKeyExchangemechanism
using HTML andJ avaScript. Consider the end user as
9 oneoftheparties(Alice)andtheJ avaScriptapplicationasotherparty 21-22
(bob).
CalculatethemessagedigestofatextusingtheSHA-1algorithminJAVA.
10 23-24
CalculatethemessagedigestofatextusingtheSHA-1algorithminJAVA.
11 25-26
COMPUTERSCIENCE&ENGINEERING
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
1. XORastringwithaZero
AIM: Write a C programthatcontainsastring(charpointer)withavalue
\Hello
World’.TheprogramshouldXOReachcharacterinthisstringwith0anddisplay theresult.
PROGRAM:
#include<stdlib.h>main()
{
charstr[]="HelloWorld";charstr1[11];
int
i,len;len=strlen(str);for(i=0;i<len;i++
)
{
str1[i]=str[i]^0;printf("%c",str1[i]);
}
printf("\n");
}
Output
HelloWorldHelloWorld
COMPUTERSCIENCE&ENGINEERING
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
2. XORastringwitha127
Aim:
Implement a program that contains a string with the value "HelloWorld". The program should
AND and XOR each character in this string with 127 and display the result.
PROGRAM:
#include <stdio.h>
int main() {
char *str = "HelloWorld";
char and_result[11]; // Array to store the AND result
char xor_result[11]; // Array to store the XOR result
int i;
return 0;
}
OUTPUT:
Original string: HelloWorld
Resulting string after AND with 127: HelloWorld
Resulting string after XOR with 127: 7S{{{9^{{
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Aim:
Program:
public class CaesarCipher {
public static String encrypt(String text, int shift) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
if (Character.isLetter(ch)) {
char base = Character.isLowerCase(ch) ? 'a' : 'A';
ch = (char) ((ch - base + shift) % 26 + base);
}
result.append(ch);
}
return result.toString();
}
OUTPUT:
Original text: HelloWorld
Encrypted text: KhoorZruog
Decrypted text: HelloWorld
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
B) SUBSTITUTION CIPHER
AIM:
Implement encryption and decryption using Substitution Cipher
Program:
import java.util.HashMap;
import java.util.Map;
Accredited by NAAC
OUTPUT:
Accredited by NAAC
C) HILL CIPHER
AIM:
Implement encryption and decryption using Hill Cipher.
Program:
import java.util.Scanner;
public class HillCipher {
private static int[][] keyMatrix;
private static int[] messageVector;
private static int[] cipherMatrix;
public static void main(String[] args) {
String message = "HELLOX"; // Adjusted to ensure length is divisible by 3
String key = "GYBNQKURP"; // 3x3 key matrix for simplicity
encrypt(message, key);
}
public static void encrypt(String message, String key) {
getKeyMatrix(key);
int messageLength = message.length();
messageVector = new int[3];
cipherMatrix = new int[3];
for (int i = 0; i < messageLength; i += 3) {
for (int j = 0; j < 3; j++) {
messageVector[j] = message.charAt(i + j) % 65;
}
for (int x = 0; x < 3; x++) {
cipherMatrix[x] = 0;
for (int y = 0; y < 3; y++) {
cipherMatrix[x] += keyMatrix[x][y] * messageVector[y];
}
cipherMatrix[x] = cipherMatrix[x] % 26;
}
Accredited by NAAC
Aim:
Implement the DES algorithm logic for encryption and decryption.
Program:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
Accredited by NAAC
}
}
OUTPUT:
Secret Key: iRb9Yg6z2cI=
Encrypted Text: y7upedUDmcCdcAcflOo1hw==
Decrypted Text: HelloWorld
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
5. Blowfish Algorithm
Aim:
Implement the Blowfish algorithm logic for encryption and decryption.
Program:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
Accredited by NAAC
OUTPUT:
Secret Key: e+cnAkI85Cu1/IHs2j7lOQ==
Encrypted Text: 1far+lVYKo25ZZDANd8j1w==
Decrypted Text: HelloWorld
Accredited by NAAC
6. Rijndael algorithm
Aim:
Implement the Rijndael (AES) algorithm logic for encryption and decryption.
Program:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
Accredited by NAAC
OUTPUT:
Secret Key: Z8F8FAOWyW7J3iQmiJ3DxQ==
Encrypted Text: Z4ANZUMyG37UFoFOJC1VOQ==
Decrypted Text: HelloWorld
Accredited by NAAC
Aim:
To encrypt the text "HelloWorld" using Blowfish in Java, and to create your own key using the Java
keytool
Program:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
Accredited by NAAC
OUTPUT:
Secret Key: (varies each time the program runs)
Encrypted Text: (varies each time the program runs)
Decrypted Text: HelloWorld
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Program:
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import javax.crypto.Cipher;
import java.util.Base64;
Accredited by NAAC
OUTPUT:
Encrypted Text: (varies each time the program runs)
Decrypted Text: HelloWorld
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Program:
Create an HTML file (e.g., index.html) with the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffie-Hellman Key Exchange</title>
<script>
// Function to generate a random number within a range
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Function to calculate modular exponentiation (base^exp % mod)
function modExp(base, exp, mod) {
let result = 1;
while (exp > 0) {
if (exp % 2 === 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exp = Math.floor(exp / 2);
}
return result;
}
// Generate Bob's private and public keys
function generateBobKeys() {
const p = 23; // Prime number
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Accredited by NAAC
<body>
<h1>Diffie-Hellman Key Exchange</h1>
<p>Enter Bob's public key:</p>
<input type="text" id="bobPublicKey" placeholder="Enter Bob's public key" />
<button onclick="generateAliceKeys()">Generate Alice's Keys and Shared Secret</button>
<h2>Alice's Key:</h2>
<p>Public Key: <span id="alicePublicKey"></span></p>
<p>Private Key: <span id="alicePrivateKey"></span></p>
<p>Shared Secret Key: <span id="sharedSecretKey"></span></p>
<h2>Bob's Key:</h2>
<p>Public Key: <span id="bobPublicKey"></span></p>
<p>Private Key: <span id="bobPrivateKey"></span></p>
<p>Shared Secret Key: <span id="bobSharedSecretKey"></span></p>
</body>
</html>
OUTPUT:
Accredited by NAAC
Aim:
Calculate the message digest of a text using the SHA-1 algorithm in Java.
Program:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Accredited by NAAC
OUTPUT:
Original Text: HelloWorld
SHA-1 Digest: d3486ae9136e7856bc42212385ea7970944758
KG Reddy College of Engineering & Technology
(Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad)
Chilkur (Village), Moinabad (Mandal), R. R Dist, TS-501504
Accredited by NAAC
Program:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
} catch (NoSuchAlgorithmException e) {
System.err.println("Algorithm not found.");
}
}
Accredited by NAAC
return hexString.toString();
}
}
OUTPUT:
SHA-1 Digest: db8ac1c259eb89d4a131b253bacfca5f319d54f2
MD5 Digest: 68e109f0f40ca72a15e05cc22786f8e6
Accredited by NAAC