def METHOD_NAME(word, word_len):
    global WORD_ARRAY
    global BYTEWORDS
    if len(word) != word_len:
        raise ValueError('Invalid Bytewords.')
    dim = 26
    # Since the first and last letters of each Byteword are unique,
    # we can use them as indexes into a two-dimensional lookup table.
    # This table is generated lazily.
    if WORD_ARRAY == None:
        WORD_ARRAY = [-1] * (dim * dim)  # create empty array
        for i in range(256):
            byteword_offset = i * 4
            x = ord(BYTEWORDS[byteword_offset]) - ord('a')
            y = ord(BYTEWORDS[byteword_offset + 3]) - ord('a')
            array_offset = y * dim + x
            WORD_ARRAY[array_offset] = i
    # If the coordinates generated by the first and last letters are out of bounds,
    # or the lookup table contains -1 at the coordinates, then the word is not valid.
    x = ord(word[0].lower()) - ord('a')
    y = ord((word[3 if len(word) == 4 else 1]).lower()) - ord('a')
    if not (0 <= x and x < dim and 0 <= y and y < dim):
        raise ValueError('Invalid Bytewords.')
    offset = y * dim + x
    value = WORD_ARRAY[offset]
    if value == -1:
        raise ValueError('Invalid Bytewords.')
    # If we're decoding a full four-letter word, verify that the two middle letters are correct.
    if len(word) == 4:
        byteword_offset = value * 4
        c1 = word[1].lower()
        c2 = word[2].lower()
        if c1 != BYTEWORDS[byteword_offset + 1] or c2 != BYTEWORDS[byteword_offset + 2]:
            raise ValueError('Invalid Bytewords.')
    # Successful decode.
    return value