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

Method scheduleCore

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

Subroutine of the Rijndael key expansion.

(BigInteger t, int rconCounter)

Source from the content-addressed store, hash-verified

2382 * Subroutine of the Rijndael key expansion.
2383 */
2384 public static BigInteger scheduleCore(BigInteger t, int rconCounter) {
2385 StringBuilder rBytes = new StringBuilder(t.toString(16));
2386
2387 // Add zero padding
2388 while (rBytes.length() < 8) {
2389 rBytes.insert(0, "0");
2390 }
2391
2392 // rotate the first 16 bits to the back
2393 String rotatingBytes = rBytes.substring(0, 2);
2394 String fixedBytes = rBytes.substring(2);
2395
2396 rBytes = new StringBuilder(fixedBytes + rotatingBytes);
2397
2398 // apply S-Box to all 8-Bit Substrings
2399 for (int i = 0; i < 4; i++) {
2400 StringBuilder currentByteBits = new StringBuilder(rBytes.substring(i * 2, (i + 1) * 2));
2401
2402 int currentByte = Integer.parseInt(currentByteBits.toString(), 16);
2403 currentByte = SBOX[currentByte];
2404
2405 // add the current RCON value to the first byte
2406 if (i == 0) {
2407 currentByte = currentByte ^ RCON[rconCounter];
2408 }
2409
2410 currentByteBits = new StringBuilder(Integer.toHexString(currentByte));
2411
2412 // Add zero padding
2413 while (currentByteBits.length() < 2) {
2414 currentByteBits.insert(0, '0');
2415 }
2416
2417 // replace bytes in original string
2418 rBytes = new StringBuilder(rBytes.substring(0, i * 2) + currentByteBits + rBytes.substring((i + 1) * 2));
2419 }
2420
2421 return new BigInteger(rBytes.toString(), 16);
2422 }
2423
2424 /**
2425 * Returns an array of 10 + 1 round keys that are calculated by using

Callers 1

keyExpansionMethod · 0.95

Calls 4

lengthMethod · 0.80
parseIntMethod · 0.80
toStringMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected