software-defined-networks-ccs365
software-defined-networks-ccs365
q[n]=toupper(*p + (char)3);
else if(*p=='x')
q[n]='A';
else if(*p=='y')
q[n]='B';
else
q[n]='C';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]='\0';
puts(q);
}
void decrypt(char*str)
{
int n=0;
char *p=str,
q[MAXSIZE];
while(*p)
{
if(isupper(*p))
{
if((*p>='D')&&(*p<='Z'))
q[n]=tolower(*p - (char)3);
else if(*p=='A')
q[n]='x';
else if(*p=='B')
q[n]='y';
else
q[n]='z';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]='\0';
puts(q);
}
int menu()
{
puts("To encrypt, input e or E\n");
puts("To decrypt, input d or D\n");
puts("To exit, input any other letter\n");
puts("Your choice:->\n");
return 0;
}
Output:
Encrypt -----e or E
Decrypt------d or D
} else {
arr[i][j]=message[k++];
}
}
}
r=i;
c=j;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
prin琀昀("%c ",arr[i][j]);
}
prin琀昀("\n");
}
k=0;
for (i=0;i<klen;i++) {
index=昀椀ndMin();
cipher(index,r);
}
emessage[k]='\0';
prin琀昀("\nEncrypted message is\n");
for (i=0;emessage[i]!=NULL;i++)
prin琀昀("%c",emessage[i]);
prin琀昀("\n\n");
//deciphering
emlen=strlen(emessage);
//emlen is length of encrypted message
strcpy(temp,key);
rows=emlen/klen;
//rows is no of row of the array to made from ciphered message
j=0;
for (i=0,k=1;emessage[i]!=NULL;i++,k++) {
//prin琀昀("\nEmlen=%d",emlen);
temp2[j++]=emessage[i];
if((k%rows)==0) {
temp2[j]='\0';
index=昀椀ndMin();
makeArray(index,rows);
j=0;
}
}
prin琀昀("\nArray Retrieved is\n");
k=0;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
prin琀昀("%c ",darr[i][j]);
//retrieving message
retmessage[k++]=darr[i][j];
}
prin琀昀("\n");
}
retmessage[k]='\0';
{
c=昀椀ndColumn(key[i]);
r=昀椀ndDecRow(emessage[i],c);
retMessage[i]=arr[r][0];
}
retMessage[i]='\0';
prin琀昀("\n\nMessage Retrieved is:\n\n");
for(i=0;retMessage[i]!=NULL;i++)
prin琀昀("%c",retMessage[i]);
getch();
return(0);
}
int 昀椀ndRow(char c)
{
int i;
for(i=0;i<26;i++)
{
if(arr[0][i]==c)
return(i);
}
}
int 昀椀ndColumn(char c)
{
int i;
for(i=0;i<26;i++)
{
if(arr[i][0]==c)
return(i);
}
}
int 昀椀ndDecRow(char c,int j)
{
int i;
for(i=0;i<26;i++)
{
if(arr[i][j]==c)
return(i);
}
}
Output:
{
d[j]=c[i];
j=j+2;
}
d[l]='\0';
prin琀昀("\nText a昀琀er decryp琀椀on : ");
prin琀昀("%s",d);
getch();
}
Output
import javax.swing.*;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.u琀椀l.Random ;
class DES {
String skeyString;
String inputMessage,encryptedData,decryptedMessage;
public DES() {
try {
generateSymmetricKey();
catch(Excep琀椀on e) {
System.out.println(e);
void generateSymmetricKey() {
try {
skey=getRawKey(knumb);
catch(Excep琀椀on e) {
System.out.println(e);
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(56, sr);
raw = skey.getEncoded();
return raw;
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
return encrypted;
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
return decrypted;
Output:
Program
import java.io.UnsupportedEncodingExcep琀椀on;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmExcep琀椀on;
import java.u琀椀l.Arrays;
import java.u琀椀l.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
MessageDigestsha = null;
try {
key = myKey.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
catch (NoSuchAlgorithmExcep琀椀on e) {
e.printStackTrace();
catch (UnsupportedEncodingExcep琀椀on e) {
e.printStackTrace();
try
setKey(secret);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));
catch (Excep琀椀on e)
return null;
try
setKey(secret);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
catch (Excep琀椀on e)
return null;
System.out.println(originalString);
System.out.println(encryptedString);
System.out.println(decryptedString);
Output:
Plain Text:howtodoinjava.com
howtodoinjava.com
Result:Thus AES algorithm was executed and output was verified successfully.
ALGORITHM :
Key generation:
1. Select random prime numbers p and q , and check that p != q
2. Compute modulus n = pq
3. Compute phi, ¢ = (p - 1)(q - 1)
4. Select public exponent e , 1 < e < ¢ . such that gcd(e, ¢ ) = 1
5. Compute private exponent d =e-1 mod ¢
6. Public key is {n, e}, private key is d
Encryption & Decryption
7. Encryption: c = memod n ,
9. Decryption: m = cdmod n
10. Display the cipher text and plain text.
Program
<html>
<head>
</head>
<body>
<br/><br/>
<br/><br/>
<h3>Encrypted value</h3>
<p id="encrypted"></p>
<br/><br/>
<br/><br/>
<h3>Decrypted value</h3>
<p id="decrypted"></p>
<script src="rsa.js"></script>
<script type="text/javascript">
func琀椀on RSA_encryp琀椀on(){
encrypt.setPublicKey(pubilc_key);
document.getElementById("encrypted").innerHTML = encrypted;
func琀椀on RSA_decryp琀椀on(){
BmkD6wySXgp8Th1M9EKnhS6zsAtKh昀戀K1oY4H2RZuAQ9TCYD0BIM7pU5GcJTjQD8ShsU269N8lFcERt
dTbldjtOpAoGAF4YkADAa6lhjXg0loY2Gk9hdFji913QZuMaOLtYnkNO3zWSSWc85ut4Svxc1R1vOSz89e
qgwo7vqbHXYQken4jOckXCgGZq昀琀nERe6HJgeCTsby8PxOAdVUBuHqF3J7VH2xlY7eTo4+GVsSNFq0nH
CRm6/
RmW9ohdeXh6k7CLAsCgYBZe3RLWu昀昀Kxg+lZmv9tJDOO813QPLFeixrBYhKjGDcwjVYcCugGNDmyStM
0/++uWddgMKavNALjpamu8KolDNivrjL1qaFHX9Bpi108T+dDn2WpX+vUP6hjA/
U2wtTvUbJle1SsbZxRrV9gf5PAJqTrQY4u28ezjR3PCV+R4kdw==-----END PRIVATE KEY-----";
decrypt.setPrivateKey(private_key);
document.getElementById("decrypted").innerHTML = decrypted;
</script>
</body>
</html>
Website Link
h琀琀p://琀椀tan.csit.rmit.edu.au/~e23700/Lab8/demo1/test_rsa.html
AIM : To write a C++ program to Implement Diffie Hellman key exchange Algorithm.
ALGORITHM :
1. Enter the value of n and g, both are prime numbers.
2. Enter x and y and these are private chosen by the users alice and bob respectively.
3. Alice calculates g x mod n and Bob calculates g y mod n
4. Bob sends the value g y mod n to Alice and alice sends the value g x mod n to Bob.
5. Alice will calculate the shared secret by (g y mod n )x mod n and bob by
(g x mod n )y mod n.
6 . Display the shared secret key.
Program:
#include<conio.h>
#include<iostream.h>
#include<math.h>
int alice(int,int,int);
int bob(int,int,int);
void main()
{
long int g,x,y,a,b,k1,k2,n;
clrscr();
cout<<"\n\t Enter value of n & g";
cin>>n>>g;
cout<<"\n\t Enter value of x & y";
cin>>x>>y;
a=alice(n,g,x);
cout<<"\n\t alice end value:"<<a;
b=bob(n,g,y);
cout<<"\n\t bob end value:"<<b;
k1=alice(n,b,x);
cout<<"\n\t valueof k1 :"<<k1;
k2=alice(n,a,y);
cout<<"\n\t valueof k2 :"<<k2;
getch();
}
int alice(int n,int g,int x)
{
ALGORITHM :
1. Input the plain text
2. Append padding bits
3. Append length
4. Initialize buffer.
5. Process message in 512-bit (16word)blocks
6. Encrypted in hexa decimal format
7. Display the encrypted text.
Program
import java.security.*;
class JceSha1Test {
public static void main(String[] a) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = "+md.getAlgorithm());
System.out.println(" Provider = "+md.getProvider());
System.out.println(" toString = "+md.toString());
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") =");
System.out.println(" "+bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") =");
System.out.println(" "+bytesToHex(output));
} catch (Exception e) {
System.out.println("Exception: "+e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
OUTPUT
3. Create the signature with components private key and global public key.
4. Send the msg along with signature.
5. Verify the signature by calculating hash value and public key and global public key.
6. If If the hash value matches signature is verified.
Program:
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.Signature;
import java.io.*;
//import java.util;
public class SignatureTest {
private static byte[] sign(String datafile, PrivateKey prvKey, String sigAlg) throws Exception {
Signature sig = Signature.getInstance(sigAlg);
sig.initSign(prvKey);
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = fis.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = fis.read(dataBytes);
};
return sig.sign();
}
private static boolean verify(String datafile, PublicKey pubKey, String sigAlg, byte[] sigbytes)
throws Exception {
Signature sig = Signature.getInstance(sigAlg);
sig.initVerify(pubKey);
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = fis.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = fis.read(dataBytes);
};
return sig.verify(sigbytes);
}
try {
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(kp);
out.close();
}
catch(IOException ex) {
ex.printStackTrace();
}
//now try to recover it from the file
FileInputStream fis = null;
ObjectInputStream in = null;
KeyPair newkp = null;
try
{
fis = new FileInputStream(filename);
in = new ObjectInputStream(fis);
newkp = (KeyPair)in.readObject();
in.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
System.out.println(prvk.toString());
System.out.println(newprvk.toString());
}}
Output:
INSTALLATION PROCEDURE
1. Download SNORT from snort.org
STEPS
SNORT can be configured to run in three modes:
1. Sniffer mode 2. Packet Logger mode 3. Network Intrusion Detection System mode
Sniffer mode
i. snort –v Print out the TCP/IP packets header on the screen
ii. snort –vd Show the TCP/IP ICMP header with application data in transit.
Packet Logger mode
i. snort –dev –l c:\log snort will automatically know to go into packet logger mode, it
collects every packet it sees and places it in log directory.
ii. snort –dev –l c:\log –h ipaddress/24 This rule tells snort that you want to print out
the data link and TCP/IP headers as well as application data into the log directory.
iii. snort –l c:\log –b This is binary mode logs everything into a single file.
Network Intrusion Detection System mode
i. snort –d c:\log –h ipaddress/24 –c snort.conf This is a configuration file applies rule
to each packet to decide it an action based upon the rule type in the file.
ii. snort –d –h ipaddress/24 –l c:\log –c snort.conf This will configure snort to run in
its most basic NIDS form, logging packets that trigger rules specifies in the snort.conf
C:\Snort\bin\snort –v
C:\Snort\bin\snort –vd
C:\Snort\bin\snort –l c:\log –b
EXECUTION
Result:Thus root kit hunter installation and its variety of operations were studied
successfully.