All pastes #83132 Raw Edit

Neronix

public text v1 · immutable
·published 2006-07-09 10:58 UTC
rendered paste body
-- Before
local CRC_LIMIT = tonumber("FFFF", 16)

local function CheckSum(text)
    local counter = 1
    
    for i = 1,string.len(text) do
        counter = counter + (string.byte(text, i) * 17 * i)
    end
    
    counter = math.mod(counter, CRC_LIMIT)
    return string.format("%04X", counter)
end

-- After
local CRC_LIMIT = tonumber("FFFFFF", 16)

local function CheckSum(text)
    local counter = 1
    
    for i = 1,string.len(text) do
        counter = counter + (string.byte(text, i) * 17 * i)
    end
    
    counter = math.mod(counter, CRC_LIMIT)
    return string.format("%06X", counter)
end