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
)); }}
aW1wb3J0IGphdmF4LmNyeXB0by5DaXBoZXI7CmltcG9ydCBqYXZhLnV0aWwuU2Nhbm5lcjsKaW1wb3J0IGphdmF4LmNyeXB0by5zcGVjLlNlY3JldEtleVNwZWM7CgpwdWJsaWMgY2xhc3MgYmxvd2Zpc2gKewpwdWJsaWMgc3RhdGljIGJ5dGVbXSBlbmNyeXB0KGJ5dGVbXSBwbGFpbnRleHQgLGJ5dGVbXWtleSkgdGhyb3dzIEV4Y2VwdGlvbgp7CiBDaXBoZXIgY2lwaGVyPUNpcGhlci5nZXRJbnN0YW5jZSgiYmxvd2Zpc2giKTsKIGNpcGhlci5pbml0KENpcGhlci5FTkNSWVBUX01PREUsbmV3IFNlY3JldEtleVNwZWMoa2V5LCJibG93ZmlzaCIpKTsKIHJldHVybiBjaXBoZXIuZG9GaW5hbChwbGFpbnRleHQpOwogfQogcHVibGljIHN0YXRpYyBieXRlW10gZGVjcnlwdChieXRlW10gY2lwaGVydGV4dCAsYnl0ZVtda2V5KSB0aHJvd3MgRXhjZXB0aW9uCnsKIENpcGhlciBjaXBoZXI9Q2lwaGVyLmdldEluc3RhbmNlKCJibG93ZmlzaCIpOwogY2lwaGVyLmluaXQoQ2lwaGVyLkRFQ1JZUFRfTU9ERSxuZXcgU2VjcmV0S2V5U3BlYyhrZXksImJsb3dmaXNoIikpOwogcmV0dXJuIGNpcGhlci5kb0ZpbmFsKGNpcGhlcnRleHQpOwogfQogICAKICAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKQogICAgIHsKICAgICBieXRlW11rZXk9Im15IHNlY3JldCBrZXkiLmdldEJ5dGVzKCk7CiAgICAgU2Nhbm5lciBzYz1uZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgIFN5c3RlbS5vdXQucHJpbnRsbigiZW50ZXIgdGhlIHBsYWludGV4dCIpOwogICAgIGJ5dGVbXXBsYWludGV4dD1zYy5uZXh0TGluZSgpLmdldEJ5dGVzKCk7CiAgICAgYnl0ZVtdY2lwaGVydGV4dD1lbmNyeXB0KHBsYWludGV4dCxrZXkpOwogICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQ2lwaGVydGV4dDoiK25ldyBTdHJpbmcoY2lwaGVydGV4dCkpOwogICAgIGJ5dGVbXWRlY3J5cHRlZD1kZWNyeXB0KGNpcGhlcnRleHQsa2V5KTsKICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkRlY3J5cHRlZDoiK25ldyBTdHJpbmcoZGVjcnlwdGVkKSk7CiAgICAgfX0KICAgICAK
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));
}}