Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Search for a cipher algorithms you would like to use in an application for encrypting and decrypting text messages. List your chosen algorithms. 1.blowfish

1. Search for a cipher algorithms you would like to use in an application for encrypting and decrypting text messages. List your chosen algorithms.
1.blowfish
2. For the listed algorithms, write a java program to read some text message, encrypt the message, and display the result.
3
. For the listed algorithms, write a java program to read some encrypted message, decrypt the message, and display the result.
hint(it should be read from the user )
this is the question up and I want you to fix my code
in java language
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner myObj = new Scanner (System.in);
System.out.println("choose a number for 1-encrypt 2-decrypt");
int encrypting = myObj .nextInt () ;
KeyGenerator keyGen = KeyGenerator.getInstance("Blowfish");
keyGen.init(128); // 128-bit key size
SecretKey secretKey = keyGen.generateKey();
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "Blowfish");
if (encrypting==1){
System.out.println("Enter your letter you want to encrypting");
Scanner myOb = new Scanner (System.in);
String message = myOb.nextLine() ;
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Encrypt the message and display the result
byte[] encryptedMessage = cipher.doFinal(message.getBytes());
System.out.println("Encrypted Message: " + new String(encryptedMessage));}
//new
if (encrypting==2){
System.out.println("Enter your letter you want to decryption");
Scanner kb = new Scanner (System.in);
String messageDec = kb.nextLine() ;
byte[] encryptedMessage = // encrypted message to decrypt
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
// Decrypt the message and display the result
byte[] decryptedMessage = cipher.doFinal(messageDec.getBytes());
System.out.println("Decrypted Message: " + new String(decryptedMessage));
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

=+1. Are you happy with the results?

Answered: 1 week ago

Question

Describe various competitive compensation policies.

Answered: 1 week ago