S-Aes Code Python
S-Aes Code Python
# S-Box
sBox = [
0x9,
0x4,
0xA,
0xB,
0xD,
0x1,
0x8,
0x5,
0x6,
0x2,
0x0,
0x3,
0xC,
0xE,
0xF,
0x7,
]
# Inverse S-Box
sBoxI = [
0xA,
0x5,
0x9,
0xB,
0x1,
0x7,
0x8,
0xF,
0x6,
0x0,
0x2,
0x3,
0xC,
0x4,
0xD,
0xE,
]
# Round constants
Rcon1 = 0x80
Rcon2 = 0x30
return (
self.int_to_state((w[0] << 8) + w[1]), # Pre-Round key
self.int_to_state((w[2] << 8) + w[3]), # Round 1 key
self.int_to_state((w[4] << 8) + w[5]), # Round 2 key
)
# If LSB of b is 1
if b & 1:
# Update b to b // 2
b = b >> 1
return product
state = self.mix_columns(self.shift_rows(self.sub_nibbles(self.sBox,
state)))
return self.state_to_int(state)
state = self.inverse_mix_columns(self.add_round_key(self.round1_key,
state))
return self.state_to_int(state)