Skip to content

Instantly share code, notes, and snippets.

@pun1sher729
Last active May 18, 2022 19:25
Show Gist options
  • Save pun1sher729/0a498c2695789af22e685baac69ecec5 to your computer and use it in GitHub Desktop.
Save pun1sher729/0a498c2695789af22e685baac69ecec5 to your computer and use it in GitHub Desktop.
Cryptohack - Structure of AES writeup
def bytes2matrix(text):
    """ Converts a 16-byte array into a 4x4 matrix.  """
    return [list(text[i:i+4]) for i in range(0, len(text), 4)]

def matrix2bytes(matrix):
    """ Converts a 4x4 matrix into a 16-byte array.  """
    out = []
    for r in matrix:
        for c in r:
            out.append(c.to_bytes(2,byteorder='little').decode())
    return ''.join(out)

matrix = [
    [99, 114, 121, 112],
    [116, 111, 123, 105],
    [110, 109, 97, 116],
    [114, 105, 120, 125],
]

print(matrix2bytes(matrix))

flag = crypto{inmatrix}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment