Skip to content

Commit 7108ef9

Browse files
committed
Added I/O
Added basic command line I/O functionality
1 parent 96d78e6 commit 7108ef9

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

ciphers/AES.java

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ciphers;
22

33
import java.math.BigInteger;
4+
import java.util.Scanner;
45

56
/* This class is build to demonstrate the
67
* apllication of the AES-algorithm on
@@ -521,23 +522,33 @@ public static BigInteger decrypt(BigInteger ciphertext, BigInteger key) {
521522
}
522523

523524
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));
532525

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));
537549
}
538550

539-
System.out.println(output.toString(16));
540-
551+
input.close();
541552
}
542553

543554
}

0 commit comments

Comments
 (0)