I would instinctively do something like
for i=1, #data, 8 do
local a, b, c, d, e, f, g, h = string.byte(data, i, i + 7)
freq[1 + (a or 256)] += 1
freq[1 + (b or 256)] += 1
freq[1 + (c or 256)] += 1
freq[1 + (d or 256)] += 1
freq[1 + (e or 256)] += 1
freq[1 + (f or 256)] += 1
freq[1 + (g or 256)] += 1
freq[1 + (h or 256)] += 1
end
Although using two loops to avoid or
might be slightly worthwhile.