fork download
  1. def bytes2matrix(text):
  2. """ Converts a 16-byte array into a 4x4 matrix. """
  3. return [list(text[i:i+4]) for i in range(0, len(text), 4)]
  4.  
  5. def matrix2bytes(matrix):
  6. """ Converts a 4x4 matrix into a 16-byte array. """
  7. return bytes(sum(matrix, []))
  8.  
  9. matrix = [
  10. [99, 114, 121, 112],
  11. [116, 111, 123, 105],
  12. [110, 109, 97, 116],
  13. [114, 105, 120, 125],
  14. ]
  15.  
  16. print(matrix2bytes(matrix))
  17.  
Success #stdin #stdout 0.03s 9740KB
stdin
Standard input is empty
stdout
b'crypto{inmatrix}'