Added I/O
Added basic command line I/O functionality
This commit is contained in:
parent
96d78e641e
commit
7108ef9045
@ -1,6 +1,7 @@
|
||||
package ciphers;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Scanner;
|
||||
|
||||
/* This class is build to demonstrate the
|
||||
* apllication of the AES-algorithm on
|
||||
@ -522,22 +523,32 @@ public class AES {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
boolean encrypt = false;
|
||||
BigInteger key = new BigInteger("0", 16);
|
||||
BigInteger plaintext = new BigInteger("0", 16);
|
||||
BigInteger ciphertext = new BigInteger("adcfc0ed15292419cb796167bc02b669", 16);
|
||||
BigInteger output;
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
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) {
|
||||
output = encrypt(plaintext, key);
|
||||
} else {
|
||||
output = decrypt(ciphertext, key);
|
||||
System.out.println("The encrypted message is: \n" + encrypt(plaintext,key).toString(16));
|
||||
}
|
||||
if(choice =='D' || choice =='d'){
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user