Try replacing this line:
local byteBefore = message_bytes:raw(i-1,1)
With this one:
local byteBefore = message_bytes:get_index(i - 1)