Method: CRC::Calculator#unshiftbytes_by_bitbybit
- Defined in:
- lib/crc/_shift.rb
#unshiftbytes_by_bitbybit(byteset, state) ⇒ Object
call-seq:
unshiftbytes_by_bitbybit(byteset, state)
byteset を与えることで state となるような内部状態を逆算します。
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/crc/_shift.rb', line 107 def unshiftbytes_by_bitbybit(byteset, state) if reflect_input? poly = (CRC.bitreflect(polynomial, bitsize) << 1) | 1 head = bitsize byteset.reverse_each_byte do |b| 7.downto(0) do |i| state <<= 1 state ^= poly unless state[head] == 0 state ^= b[i] end end state else Aux.(bitsize, state, polynomial, bitmask) do |s, poly, csh, head, carries| headbit = 1 << head lowoff = (head + 1) - bitsize poly = (poly >> 1) | headbit byteset.reverse_each_byte do |b| 8.times do |i| tmp = s[lowoff] s >>= 1 s ^= poly unless tmp == 0 s ^= b[i] << head end end s end end end |