Class: Ruckus::Mutator::Hibit

Inherits:
Modifier show all
Defined in:
lib/ruckus/mutator.rb

Overview

Randomly sets the top bit of each byte, turning ASCII into hi-ASCII.

Instance Method Summary collapse

Methods inherited from Modifier

#<<, #go?

Constructor Details

#initialize(opts = {}) ⇒ Hibit

Returns a new instance of Hibit.



241
242
243
244
245
# File 'lib/ruckus/mutator.rb', line 241

def initialize(opts={})
    opts[:prob] ||= 50
    @width = opts[:width] || 32
    super
end

Instance Method Details

#mod(x) ⇒ Object



247
248
249
250
251
252
253
254
255
256
# File 'lib/ruckus/mutator.rb', line 247

def mod(x)
    if x.kind_of? String
        0.upto(x.size - 1) do |i|
            x[i] |= 0x80 if go?
        end
    else
        x |= (0x80 << (@width - 8))
    end
    return x
end