1.AES for usingthe java(subjectnetworksecurity)
package aes;
importjava.io.*;
classCaesarCipher
{
publicstaticvoidmain(String[]args) throwsException
{
Stringpt,ct;
intkey=3;
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
System.out.print("EnterPlainText:");
pt = br.readLine().toUpperCase();
ct = doEncrypt(pt,key);
System.out.println("CipherText:" + ct);
pt = doDecrypt(ct,key);
System.out.println("DecryptedPlainText:" + pt);
}
staticString doEncrypt(Stringpt,intkey)
{
char c;
intnum;
StringBuffersb=newStringBuffer(pt);
for(inti=0;i<sb.length();i++)
{
num= sb.charAt(i)-65;
num+=key;
if(num>=26) num-=26;
c = (char)(num+65);
sb.setCharAt(i,c);
}
returnnewString(sb);
}
staticString doDecrypt(Stringct,intkey)
{
returndoEncrypt(ct,26-key).toLowerCase();
}
}
2. blowfishusingthe java
package blowfish;
importjavax.crypto.Cipher;
importjavax.crypto.spec.SecretKeySpec;
importsun.misc.BASE64Decoder;
importsun.misc.BASE64Encoder;
publicclassBlowfish{
publicstaticvoidmain(String[] args) throwsException{
encrypt("edwin","password");
decrypt("6VsVtA/nhHKUZuWWmod/BQ==");
}
private staticvoidencrypt(Stringusername,Stringpassword) throwsException{
byte[] keyData=(username+password).getBytes();
SecretKeySpecsecretKeySpec=newSecretKeySpec(keyData,"Blowfish");
Ciphercipher=Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE,secretKeySpec);
byte[] hasil =cipher.doFinal(password.getBytes());
System.out.println(new BASE64Encoder().encode(hasil));
}
private staticvoid decrypt(Stringstring) throwsException{
byte[] keyData=("edwin"+"password").getBytes();
SecretKeySpecsecretKeySpec=newSecretKeySpec(keyData,"Blowfish");
Ciphercipher=Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE,secretKeySpec);
byte[] hasil =cipher.doFinal(new BASE64Decoder().decodeBuffer(string));
System.out.println(new String(hasil));
}
}
3. CaesarCipher
package caesarcipher;
importjava.io.*;
publicclassCaesarCipher
{
publicstaticvoidmain(String[]args) throwsException
{
Stringpt,ct;
intkey=3;
BufferedReaderbr= new BufferedReader(new InputStreamReader(System.in));
System.out.print("EnterPlainText:");
pt = br.readLine().toUpperCase();
ct = doEncrypt(pt,key);
System.out.println("CipherText:" + ct);
pt = doDecrypt(ct,key);
System.out.println("DecryptedPlainText:" + pt);
}
staticString doEncrypt(Stringpt,intkey)
{
char c;
intnum;
StringBuffersb= newStringBuffer(pt);
for(inti=0;i<sb.length();i++)
{
num= sb.charAt(i)-65;
num+=key;
if(num>=26) num-=26;
c = (char)(num+65);
sb.setCharAt(i,c);
}
returnnewString(sb);
}
staticvoiddoDecrypt(Stringct,intkey)
{
returndoEncrypt(ct,26-key).toLowerCase();
}
}
4. package des;
importjava.io.*;
importjavax.crypto.*;
importjava.security.spec.*;
importsun.misc.*;
publicclassDES
{
publicstaticvoidmain(String[]args) throwsException
{
Stringpt,ct;
SecretKeykey;
BufferedReaderbr= new BufferedReader(new InputStreamReader(System.in));
System.out.print("EnterPlainText:");
pt = br.readLine();
key= KeyGenerator.getInstance("DES").generateKey();
ct = doEncrypt(pt,key);
System.out.println("CipherText:" + ct);
pt = doDecrypt(ct,key);
System.out.println("DecryptedPlainText:" + pt);
}
staticString doEncrypt(Stringpt,SecretKeykey)throwsException
{
Cipherc = Cipher.getInstance("DES");
c.init(Cipher.ENCRYPT_MODE,key);
byte[] utf8= pt.getBytes("UTF8");
byte[] enc= c.doFinal(utf8);
Stringstr = newBASE64Encoder().encode(enc);
returnstr;
}
staticString doDecrypt(Stringct,SecretKeykey)throwsException
{
Cipherc = Cipher.getInstance("DES");
c.init(Cipher.DECRYPT_MODE,key);
byte[] enc= newBASE64Decoder().decodeBuffer(ct);
byte[] utf8= c.doFinal(enc);
Stringstr = newString(utf8,"UTF8");
returnstr;
}etwork
}

Network security

  • 1.
    1.AES for usingthejava(subjectnetworksecurity) package aes; importjava.io.*; classCaesarCipher { publicstaticvoidmain(String[]args) throwsException { Stringpt,ct; intkey=3; BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in)); System.out.print("EnterPlainText:"); pt = br.readLine().toUpperCase(); ct = doEncrypt(pt,key); System.out.println("CipherText:" + ct); pt = doDecrypt(ct,key); System.out.println("DecryptedPlainText:" + pt); } staticString doEncrypt(Stringpt,intkey) { char c; intnum;
  • 2.
    StringBuffersb=newStringBuffer(pt); for(inti=0;i<sb.length();i++) { num= sb.charAt(i)-65; num+=key; if(num>=26) num-=26; c= (char)(num+65); sb.setCharAt(i,c); } returnnewString(sb); } staticString doDecrypt(Stringct,intkey) { returndoEncrypt(ct,26-key).toLowerCase(); } } 2. blowfishusingthe java package blowfish; importjavax.crypto.Cipher; importjavax.crypto.spec.SecretKeySpec; importsun.misc.BASE64Decoder;
  • 3.
    importsun.misc.BASE64Encoder; publicclassBlowfish{ publicstaticvoidmain(String[] args) throwsException{ encrypt("edwin","password"); decrypt("6VsVtA/nhHKUZuWWmod/BQ=="); } privatestaticvoidencrypt(Stringusername,Stringpassword) throwsException{ byte[] keyData=(username+password).getBytes(); SecretKeySpecsecretKeySpec=newSecretKeySpec(keyData,"Blowfish"); Ciphercipher=Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE,secretKeySpec); byte[] hasil =cipher.doFinal(password.getBytes()); System.out.println(new BASE64Encoder().encode(hasil)); } private staticvoid decrypt(Stringstring) throwsException{ byte[] keyData=("edwin"+"password").getBytes(); SecretKeySpecsecretKeySpec=newSecretKeySpec(keyData,"Blowfish"); Ciphercipher=Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE,secretKeySpec); byte[] hasil =cipher.doFinal(new BASE64Decoder().decodeBuffer(string)); System.out.println(new String(hasil));
  • 4.
    } } 3. CaesarCipher package caesarcipher; importjava.io.*; publicclassCaesarCipher { publicstaticvoidmain(String[]args)throwsException { Stringpt,ct; intkey=3; BufferedReaderbr= new BufferedReader(new InputStreamReader(System.in)); System.out.print("EnterPlainText:"); pt = br.readLine().toUpperCase(); ct = doEncrypt(pt,key); System.out.println("CipherText:" + ct); pt = doDecrypt(ct,key); System.out.println("DecryptedPlainText:" + pt); } staticString doEncrypt(Stringpt,intkey) {
  • 5.
    char c; intnum; StringBuffersb= newStringBuffer(pt); for(inti=0;i<sb.length();i++) { num=sb.charAt(i)-65; num+=key; if(num>=26) num-=26; c = (char)(num+65); sb.setCharAt(i,c); } returnnewString(sb); } staticvoiddoDecrypt(Stringct,intkey) { returndoEncrypt(ct,26-key).toLowerCase(); } } 4. package des; importjava.io.*; importjavax.crypto.*;
  • 6.
    importjava.security.spec.*; importsun.misc.*; publicclassDES { publicstaticvoidmain(String[]args) throwsException { Stringpt,ct; SecretKeykey; BufferedReaderbr= newBufferedReader(new InputStreamReader(System.in)); System.out.print("EnterPlainText:"); pt = br.readLine(); key= KeyGenerator.getInstance("DES").generateKey(); ct = doEncrypt(pt,key); System.out.println("CipherText:" + ct); pt = doDecrypt(ct,key); System.out.println("DecryptedPlainText:" + pt); } staticString doEncrypt(Stringpt,SecretKeykey)throwsException { Cipherc = Cipher.getInstance("DES"); c.init(Cipher.ENCRYPT_MODE,key);
  • 7.
    byte[] utf8= pt.getBytes("UTF8"); byte[]enc= c.doFinal(utf8); Stringstr = newBASE64Encoder().encode(enc); returnstr; } staticString doDecrypt(Stringct,SecretKeykey)throwsException { Cipherc = Cipher.getInstance("DES"); c.init(Cipher.DECRYPT_MODE,key); byte[] enc= newBASE64Decoder().decodeBuffer(ct); byte[] utf8= c.doFinal(enc); Stringstr = newString(utf8,"UTF8"); returnstr; }etwork }