MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / decrypt

Method decrypt

src/main/java/com/thealgorithms/ciphers/AES.java:2717–2737  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)) {

Callers 15

mainMethod · 0.95
testWithEmptyMessageMethod · 0.45
testWithEmptyKeyMethod · 0.45
testDecryptMethod · 0.45
testEmptyMessageMethod · 0.45
testSpecialCharactersMethod · 0.45

Calls 5

keyExpansionMethod · 0.95
addRoundKeyMethod · 0.95
shiftRowsDecMethod · 0.95
subBytesDecMethod · 0.95
mixColumnsDecMethod · 0.95

Tested by 15

testWithEmptyMessageMethod · 0.36
testWithEmptyKeyMethod · 0.36
testDecryptMethod · 0.36
testEmptyMessageMethod · 0.36
testSpecialCharactersMethod · 0.36
autokeyDecryptTestMethod · 0.36