Java Implementing RC4 Algorithm

 Implementing RC4 Algorithm

Code :
            import.java.io.*;
class RC4Demo
{
String strPlain;
static char cipher[];
RC4Demo(String strPlain,int[] key)
{
this.strPlain=strPlain;
int s[]=new int[255];
cipher=new  char[strPlain.length()];
for(int i=0;i<s.length;i++)
{
s[i]=i;
}
int i=0;
int j=0;
for(int k=0;k<strPlain.length();k++)
{
int modk=(k%key.length);
int kc=key[modk];
j=(s[i]+j+kc)%256+1;
int temp=s[i];
s[i]=s[j];
s[j]=temp;
int sc=(s[i]+s[j])%256;
int ck=s[sc];
cipher[k]=(char)(ck^(int)strPlain.charAt(k));
i=i+1;
}
}
public static void main(String[] args)
{
int k[]={1,2,3,4,5};
String strOriginal="hello world";
System.out.println("Original String---->"+strOriginal);
new RC4Demo(strOriginal,k);
for(int i=0;i<cipher.length;i++)
{
System.out.print(" "+cipher[i]);
}
}
}

Java Implementing BlowFish Algorithm

 Implementing BlowFish Algorithm:

Code:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class BlowFishCipher
{
public static void main(String[] args)throws Exception
{
KeyGenerator keygen=KeyGenerator.getInstance("Blowfish");
SecretKey sk=keygen.generateKey();
Cipher cip=Cipher.getInstance("Blowfish");
cip.init(Cipher.ENCRYPT_MODE,sk);

String inputText="Hello";
byte[] encrypted=cip.doFinal(inputText.getBytes());

System.out.println("Encrypted :"+new String(encrypted));
cip.init(Cipher.DECRYPT_MODE,sk);

byte[] decrypted=cip.doFinal(encrypted);
System.out.println("Decrypted :"+new String(decrypted));
System.exit(0);
}
}