Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def extend_round_key(cipher_matrix, rounds):
- rcon = [['01','00','00','00'],
- ['02','00','00','00'],
- ['04','00','00','00'],
- ['08','00','00','00'],
- ['10','00','00','00'],
- ['20','00','00','00'],
- ['40','00','00','00'],
- ['80','00','00','00'],
- ['1B','00','00','00'],
- ['36','00','00','00']]
- extended_round_key = cipher_matrix.copy() # copy the provided key to extend
- for extension in range(rounds): # perform an extension for each round
- for j in range(len(extended_round_key)): # do this four times
- for i in range(len(extended_round_key)): # do this four times
- if (len(extended_round_key[i]) % 4 == 0): # if the new position is evenly divisible by 4 do the complicated thing
- extended_round_key[i] += [bin_to_hex(xor(xor((''.join(byte_substitution(hex_to_bin(extended_round_key[(i+1)%len(extended_round_key)][len(extended_round_key[i])-1])))),hex_to_bin(extended_round_key[i][-4])),hex_to_bin(rcon[extension][i])))]
- else: # otherwise do the simple thing
- extended_round_key[i] += [bin_to_hex(xor(hex_to_bin(extended_round_key[i][-1]), hex_to_bin(extended_round_key[i][-4])))]
- return extended_round_key # return the extended key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement