You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defdecrypt(key, ciphertext):
round_keys=expand_key(key) # Remember to start from the last round key and work backwards through them when decrypting# Convert ciphertext to state matrixstate=bytes2matrix(ciphertext)
# Initial add round key stepstate=add_round_key(state, round_keys[-1])
foriinrange(N_ROUNDS-1, 0, -1):
# Do roundinv_shift_rows(state)
state=sub_bytes(state, inv_s_box)
state=add_round_key(state, round_keys[i])
inv_mix_columns(state)
# Run final round (skips the InvMixColumns step)inv_shift_rows(state)
state=sub_bytes(state, inv_s_box)
state=add_round_key(state, round_keys[0])
# Convert state matrix to plaintextplaintext=matrix2bytes(state)
returnplaintext