Module: Ronin::Support::Binary::BitFlip::String
- Defined in:
- lib/ronin/support/binary/bit_flip.rb
Overview
Methods for bit-flipping Strings.
Class Method Summary collapse
-
.bit_flips(string) ⇒ Array<String>
Returns every bit flip of every byte in the string.
-
.each_bit_flip(string) {|string| ... } ⇒ Enumerator
Enumerates over every bit flip of every byte in the string.
Class Method Details
.bit_flips(string) ⇒ Array<String>
Returns every bit flip of every byte in the string.
161 162 163 |
# File 'lib/ronin/support/binary/bit_flip.rb', line 161 def self.bit_flips(string) each_bit_flip(string).to_a end |
.each_bit_flip(string) {|string| ... } ⇒ Enumerator
Enumerates over every bit flip of every byte in the string.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ronin/support/binary/bit_flip.rb', line 131 def self.each_bit_flip(string) return enum_for(__method__,string) unless block_given? bits = (0...8) string.each_byte.with_index do |byte,index| Integer.each_bit_flip(byte,bits) do |flipped_byte| new_string = string.dup new_string.force_encoding(Encoding::ASCII_8BIT) new_string.setbyte(index,flipped_byte) yield new_string end end return nil end |