Class: Ciphr::Functions::Bitwise::BinaryTruncBitwise

Inherits:
Function
  • Object
show all
Defined in:
lib/ciphr/functions/bitwise.rb

Instance Attribute Summary

Attributes inherited from Function

#args, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

aligned, inherited, #initialize, invertable?, #prepend, #read

Constructor Details

This class inherits a constructor from Ciphr::Functions::Function

Class Method Details

.paramsObject



25
26
27
# File 'lib/ciphr/functions/bitwise.rb', line 25

def self.params
  [:input, :input]
end

.variantsObject



17
18
19
20
21
22
23
# File 'lib/ciphr/functions/bitwise.rb', line 17

def self.variants
  [
    ['and-trunc', {:op=>:&}],
    ['or-trunc', {:op=>:|}],
    [['xor-trunc'], {:op=>:'^'}]
  ]
end

Instance Method Details

#applyObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ciphr/functions/bitwise.rb', line 3

def apply
  input,keyinput = @args
  Proc.new do
    keychunk = keyinput.read(256)
    inchunk = input.read(256)
    if inchunk && keychunk
      a,b=[inchunk,keychunk].sort_by{|x| x.size}
      a.bytes.each_with_index.map{|c,i|c.send(@options[:op], b.bytes.to_a[i%b.size])}.pack("c*")
    else
      nil
    end
  end
end