class Ffc16
Constants
- MODX
Public Class Methods
checksum(buf)
click to toggle source
# File lib/ffc16.rb, line 5 def self.checksum(buf) inx = 0 end_buf = buf.length c0 = 0 c1 = 0 loop do end_chunk = (inx + MODX < end_buf) ? inx + MODX : end_buf loop do c0 += 0xff & buf[inx].ord c1 += c0 inx += 1 break unless inx < end_chunk end c0 %= 255 c1 %= 255 break unless inx < end_buf end c1 << 8 | c0 end