Encrypts the plaintext with the key and returns the result @param plainText which we want to encrypt @param key the key for encrypt @return EncryptedText
(BigInteger plainText, BigInteger key)
| 2687 | * @return EncryptedText |
| 2688 | */ |
| 2689 | public static BigInteger encrypt(BigInteger plainText, BigInteger key) { |
| 2690 | BigInteger[] roundKeys = keyExpansion(key); |
| 2691 | |
| 2692 | // Initial round |
| 2693 | plainText = addRoundKey(plainText, roundKeys[0]); |
| 2694 | |
| 2695 | // Main rounds |
| 2696 | for (int i = 1; i < 10; i++) { |
| 2697 | plainText = subBytes(plainText); |
| 2698 | plainText = shiftRows(plainText); |
| 2699 | plainText = mixColumns(plainText); |
| 2700 | plainText = addRoundKey(plainText, roundKeys[i]); |
| 2701 | } |
| 2702 | |
| 2703 | // Final round |
| 2704 | plainText = subBytes(plainText); |
| 2705 | plainText = shiftRows(plainText); |
| 2706 | plainText = addRoundKey(plainText, roundKeys[10]); |
| 2707 | |
| 2708 | return plainText; |
| 2709 | } |
| 2710 | |
| 2711 | /** |
| 2712 | * Decrypts the ciphertext with the key and returns the result |