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

Method encrypt

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

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)

Source from the content-addressed store, hash-verified

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

Callers 15

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

Calls 5

keyExpansionMethod · 0.95
addRoundKeyMethod · 0.95
subBytesMethod · 0.95
shiftRowsMethod · 0.95
mixColumnsMethod · 0.95

Tested by 15

testWithEmptyMessageMethod · 0.36
testWithEmptyKeyMethod · 0.36
testEncryptMethod · 0.36
testEmptyMessageMethod · 0.36
testSpecialCharactersMethod · 0.36
autokeyEncryptTestMethod · 0.36