fork download
  1. import javax.crypto.Cipher;
  2. import java.util.Scanner;
  3. import javax.crypto.spec.SecretKeySpec;
  4.  
  5. public class blowfish
  6. {
  7. public static byte[] encrypt(byte[] plaintext ,byte[]key) throws Exception
  8. {
  9. Cipher cipher=Cipher.getInstance("blowfish");
  10. cipher.init(Cipher.ENCRYPT_MODE,new SecretKeySpec(key,"blowfish"));
  11. return cipher.doFinal(plaintext);
  12. }
  13. public static byte[] decrypt(byte[] ciphertext ,byte[]key) throws Exception
  14. {
  15. Cipher cipher=Cipher.getInstance("blowfish");
  16. cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(key,"blowfish"));
  17. return cipher.doFinal(ciphertext);
  18. }
  19.  
  20. public static void main(String args[])
  21. {
  22. byte[]key="my secret key".getBytes();
  23. Scanner sc=new Scanner(System.in);
  24. System.out.println("enter the plaintext");
  25. byte[]plaintext=sc.nextLine().getBytes();
  26. byte[]ciphertext=encrypt(plaintext,key);
  27. System.out.println("Ciphertext:"+new String(ciphertext));
  28. byte[]decrypted=decrypt(ciphertext,key);
  29. System.out.println("Decrypted:"+new String(decrypted));
  30. }}
  31.  
  32.  
Success #stdin #stdout 0.02s 25448KB
stdin
Standard input is empty
stdout
import javax.crypto.Cipher;
import java.util.Scanner;
import javax.crypto.spec.SecretKeySpec;

public class blowfish
{
public static byte[] encrypt(byte[] plaintext ,byte[]key) throws Exception
{
 Cipher cipher=Cipher.getInstance("blowfish");
 cipher.init(Cipher.ENCRYPT_MODE,new SecretKeySpec(key,"blowfish"));
 return cipher.doFinal(plaintext);
 }
 public static byte[] decrypt(byte[] ciphertext ,byte[]key) throws Exception
{
 Cipher cipher=Cipher.getInstance("blowfish");
 cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(key,"blowfish"));
 return cipher.doFinal(ciphertext);
 }
   
     public static void main(String args[])
     {
     byte[]key="my secret key".getBytes();
     Scanner sc=new Scanner(System.in);
     System.out.println("enter the plaintext");
     byte[]plaintext=sc.nextLine().getBytes();
     byte[]ciphertext=encrypt(plaintext,key);
     System.out.println("Ciphertext:"+new String(ciphertext));
     byte[]decrypted=decrypt(ciphertext,key);
     System.out.println("Decrypted:"+new String(decrypted));
     }}