Class: Rbimg::Strategies::CRCTableLookup
- Inherits:
-
Object
- Object
- Rbimg::Strategies::CRCTableLookup
- Defined in:
- lib/strategies/crc_strategies/crc_table_lookup_strategy.rb
Constant Summary collapse
- @@crc_table =
{}
Class Method Summary collapse
Class Method Details
.crc(type, data) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/strategies/crc_strategies/crc_table_lookup_strategy.rb', line 25 def self.crc(type, data) c = ([255] * 4).pack("C4").unpack("L").first buff = type + data make_crc_table if !crc_table_computed for n in 0...buff.length c = @@crc_table[(c ^ buff[n]) & 255] ^ (c >> 8) end Byteman.int2buf(c ^ Byteman.buf2int([255] * 4)) end |
.crc_table_computed ⇒ Object
19 20 21 |
# File 'lib/strategies/crc_strategies/crc_table_lookup_strategy.rb', line 19 def self.crc_table_computed @@crc_table.length > 0 end |
.make_crc_table ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/strategies/crc_strategies/crc_table_lookup_strategy.rb', line 5 def self.make_crc_table for n in 0...256 c = n for k in 0...8 if c.odd? c = 3988292384 ^ (c >> 1) else c = c >> 1 end end @@crc_table[n] = c end end |