|
1 | 1 | package ciphers;
|
2 | 2 |
|
3 | 3 | import java.math.BigInteger;
|
| 4 | +import java.util.Scanner; |
4 | 5 |
|
5 | 6 | /* This class is build to demonstrate the
|
6 | 7 | * apllication of the AES-algorithm on
|
@@ -521,23 +522,33 @@ public static BigInteger decrypt(BigInteger ciphertext, BigInteger key) {
|
521 | 522 | }
|
522 | 523 |
|
523 | 524 | public static void main(String[] args) {
|
524 |
| - |
525 |
| - boolean encrypt = false; |
526 |
| - BigInteger key = new BigInteger("0", 16); |
527 |
| - BigInteger plaintext = new BigInteger("0", 16); |
528 |
| - BigInteger ciphertext = new BigInteger("adcfc0ed15292419cb796167bc02b669", 16); |
529 |
| - BigInteger output; |
530 |
| - |
531 |
| - System.out.println(keyExpansion(key)[2].xor(new BigInteger("9b9898c9f9fbfbaa9b9898c9f9fbfbaa",16)).toString(16)); |
532 | 525 |
|
533 |
| - if (encrypt) { |
534 |
| - output = encrypt(plaintext, key); |
535 |
| - } else { |
536 |
| - output = decrypt(ciphertext, key); |
| 526 | + Scanner input = new Scanner(System.in); |
| 527 | + |
| 528 | + System.out.println("Do you want to (e)ncrypt or (d)ecrypt a message?"); |
| 529 | + char choice = input.nextLine().charAt(0); |
| 530 | + String in; |
| 531 | + if(choice == 'E' || choice=='e'){ |
| 532 | + System.out.println("Choose a plaintext block (128-Bit Integer in base 16):\n"); |
| 533 | + in = input.nextLine(); |
| 534 | + BigInteger plaintext = new BigInteger(in, 16); |
| 535 | + System.out.println("Choose a Key (128-Bit Integer in base 16):\n"); |
| 536 | + in = input.nextLine(); |
| 537 | + BigInteger key = new BigInteger(in, 16); |
| 538 | + |
| 539 | + System.out.println("The encrypted message is: \n" + encrypt(plaintext,key).toString(16)); |
| 540 | + } |
| 541 | + if(choice =='D' || choice =='d'){ |
| 542 | + System.out.println("Enter your ciphertext block (128-Bit Integer in base 16):\n"); |
| 543 | + in = input.nextLine(); |
| 544 | + BigInteger ciphertext = new BigInteger(in, 16); |
| 545 | + System.out.println("Choose a Key (128-Bit Integer in base 16):\n"); |
| 546 | + in = input.nextLine(); |
| 547 | + BigInteger key = new BigInteger(in, 16); |
| 548 | + System.out.println("The deciphered message is:\n" + decrypt(ciphertext,key).toString(16)); |
537 | 549 | }
|
538 | 550 |
|
539 |
| - System.out.println(output.toString(16)); |
540 |
| - |
| 551 | + input.close(); |
541 | 552 | }
|
542 | 553 |
|
543 | 554 | }
|
0 commit comments