| 2737 | } |
| 2738 | |
| 2739 | public static void main(String[] args) { |
| 2740 | try (Scanner input = new Scanner(System.in)) { |
| 2741 | System.out.println("Enter (e) letter for encrypt or (d) letter for decrypt :"); |
| 2742 | char choice = input.nextLine().charAt(0); |
| 2743 | String in; |
| 2744 | switch (choice) { |
| 2745 | case 'E', 'e' -> { |
| 2746 | System.out.println( |
| 2747 | "Choose a plaintext block (128-Bit Integer in base 16):" |
| 2748 | ); |
| 2749 | in = input.nextLine(); |
| 2750 | BigInteger plaintext = new BigInteger(in, 16); |
| 2751 | System.out.println( |
| 2752 | "Choose a Key (128-Bit Integer in base 16):" |
| 2753 | ); |
| 2754 | in = input.nextLine(); |
| 2755 | BigInteger encryptionKey = new BigInteger(in, 16); |
| 2756 | System.out.println( |
| 2757 | "The encrypted message is: \n" |
| 2758 | + encrypt(plaintext, encryptionKey).toString(16) |
| 2759 | ); |
| 2760 | } |
| 2761 | case 'D', 'd' -> { |
| 2762 | System.out.println( |
| 2763 | "Enter your ciphertext block (128-Bit Integer in base 16):" |
| 2764 | ); |
| 2765 | in = input.nextLine(); |
| 2766 | BigInteger ciphertext = new BigInteger(in, 16); |
| 2767 | System.out.println( |
| 2768 | "Choose a Key (128-Bit Integer in base 16):" |
| 2769 | ); |
| 2770 | in = input.nextLine(); |
| 2771 | BigInteger decryptionKey = new BigInteger(in, 16); |
| 2772 | System.out.println( |
| 2773 | "The deciphered message is:\n" |
| 2774 | + decrypt(ciphertext, decryptionKey).toString(16) |
| 2775 | ); |
| 2776 | } |
| 2777 | default -> System.out.println("** End **"); |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | } |