Added I/O

Added basic command line I/O functionality
This commit is contained in:
Phil-Schmidt 2017-11-27 03:03:58 +01:00
parent 96d78e641e
commit 7108ef9045

View File

@ -1,6 +1,7 @@
package ciphers; package ciphers;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Scanner;
/* This class is build to demonstrate the /* This class is build to demonstrate the
* apllication of the AES-algorithm on * apllication of the AES-algorithm on
@ -522,22 +523,32 @@ public class AES {
public static void main(String[] args) { public static void main(String[] args) {
boolean encrypt = false; Scanner input = new Scanner(System.in);
BigInteger key = new BigInteger("0", 16);
BigInteger plaintext = new BigInteger("0", 16);
BigInteger ciphertext = new BigInteger("adcfc0ed15292419cb796167bc02b669", 16);
BigInteger output;
System.out.println(keyExpansion(key)[2].xor(new BigInteger("9b9898c9f9fbfbaa9b9898c9f9fbfbaa",16)).toString(16)); System.out.println("Do you want to (e)ncrypt or (d)ecrypt a message?");
char choice = input.nextLine().charAt(0);
String in;
if(choice == 'E' || choice=='e'){
System.out.println("Choose a plaintext block (128-Bit Integer in base 16):\n");
in = input.nextLine();
BigInteger plaintext = new BigInteger(in, 16);
System.out.println("Choose a Key (128-Bit Integer in base 16):\n");
in = input.nextLine();
BigInteger key = new BigInteger(in, 16);
if (encrypt) { System.out.println("The encrypted message is: \n" + encrypt(plaintext,key).toString(16));
output = encrypt(plaintext, key); }
} else { if(choice =='D' || choice =='d'){
output = decrypt(ciphertext, key); System.out.println("Enter your ciphertext block (128-Bit Integer in base 16):\n");
in = input.nextLine();
BigInteger ciphertext = new BigInteger(in, 16);
System.out.println("Choose a Key (128-Bit Integer in base 16):\n");
in = input.nextLine();
BigInteger key = new BigInteger(in, 16);
System.out.println("The deciphered message is:\n" + decrypt(ciphertext,key).toString(16));
} }
System.out.println(output.toString(16)); input.close();
} }
} }