Class: Ciphr::Functions::Bitwise::BinaryBitwise
- Inherits:
-
Function
- Object
- Function
- Ciphr::Functions::Bitwise::BinaryBitwise
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
Class Method Details
.params ⇒ Object
54
55
56
|
# File 'lib/ciphr/functions/bitwise.rb', line 54
def self.params
[:input, :input]
end
|
.variants ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/ciphr/functions/bitwise.rb', line 46
def self.variants
[
['and', {:op=>:&}],
['or', {:op=>:|}],
[['xor'], {:op=>:'^'}]
]
end
|
Instance Method Details
#apply ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ciphr/functions/bitwise.rb', line 31
def apply
input,keyinput = @args
keyb, inputb = [keyinput.read.bytes.to_a, input.read.bytes.to_a].sort_by{|a| a.size }
Proc.new do
if inputb
resb = inputb.each_with_index.map{|c,i|c.send(@options[:op], keyb[i%keyb.size])}
res = resb.pack("c*")
inputb = nil
res
else
nil
end
end
end
|