Decrypts the ciphertext with the key and returns the result @param cipherText The Encrypted text which we want to decrypt @return decryptedText
(BigInteger cipherText, BigInteger key)
| 2715 | * @return decryptedText |
| 2716 | */ |
| 2717 | public static BigInteger decrypt(BigInteger cipherText, BigInteger key) { |
| 2718 | BigInteger[] roundKeys = keyExpansion(key); |
| 2719 | |
| 2720 | // Invert final round |
| 2721 | cipherText = addRoundKey(cipherText, roundKeys[10]); |
| 2722 | cipherText = shiftRowsDec(cipherText); |
| 2723 | cipherText = subBytesDec(cipherText); |
| 2724 | |
| 2725 | // Invert main rounds |
| 2726 | for (int i = 9; i > 0; i--) { |
| 2727 | cipherText = addRoundKey(cipherText, roundKeys[i]); |
| 2728 | cipherText = mixColumnsDec(cipherText); |
| 2729 | cipherText = shiftRowsDec(cipherText); |
| 2730 | cipherText = subBytesDec(cipherText); |
| 2731 | } |
| 2732 | |
| 2733 | // Invert initial round |
| 2734 | cipherText = addRoundKey(cipherText, roundKeys[0]); |
| 2735 | |
| 2736 | return cipherText; |
| 2737 | } |
| 2738 | |
| 2739 | public static void main(String[] args) { |
| 2740 | try (Scanner input = new Scanner(System.in)) { |