Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.crypto.*;
- import java.util.Scanner;
- public class TEST {
- public static void main(String[] args) {
- try {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter the password or message: ");
- String input = scan.nextLine();
- KeyGenerator keyGen = KeyGenerator.getInstance("DES");
- SecretKey desKey = keyGen.generateKey();
- Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
- desCipher.init(Cipher.ENCRYPT_MODE, desKey);
- byte[] clearText = input.getBytes();
- byte[] cipherText = desCipher.doFinal(clearText);
- desCipher.init(Cipher.DECRYPT_MODE, desKey);
- byte[] clearText1 = desCipher.doFinal(cipherText);
- System.out.println("\n\nCLEAR TEXT: \n");
- for(int i = 0; i < clearText.length; i++) {
- System.out.print(clearText[i]);
- }
- System.out.println("\n\nCIPHER TEXT: \n");
- for(int j = 0; j < cipherText.length; j++) {
- System.out.print(cipherText[j]);
- }
- System.out.println("\n\nDECRYPTED TEXT: \n");
- for(int k = 0; k < clearText1.length; k++) {
- System.out.print(clearText1[k]);
- }
- System.out.println();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment