Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. def extend_round_key(cipher_matrix, rounds):
  2. rcon = [['01','00','00','00'],
  3. ['02','00','00','00'],
  4. ['04','00','00','00'],
  5. ['08','00','00','00'],
  6. ['10','00','00','00'],
  7. ['20','00','00','00'],
  8. ['40','00','00','00'],
  9. ['80','00','00','00'],
  10. ['1B','00','00','00'],
  11. ['36','00','00','00']]
  12. extended_round_key = cipher_matrix.copy() # copy the provided key to extend
  13. for extension in range(rounds): # perform an extension for each round
  14. for j in range(len(extended_round_key)): # do this four times
  15. for i in range(len(extended_round_key)): # do this four times
  16. if (len(extended_round_key[i]) % 4 == 0): # if the new position is evenly divisible by 4 do the complicated thing
  17. 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])))]
  18. else: # otherwise do the simple thing
  19. extended_round_key[i] += [bin_to_hex(xor(hex_to_bin(extended_round_key[i][-1]), hex_to_bin(extended_round_key[i][-4])))]
  20. return extended_round_key # return the extended key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement