Class: Ciphr::Functions::Base::Base8
- Inherits:
-
Base
show all
- Defined in:
- lib/ciphr/functions/base_radix.rb
Instance Attribute Summary
#invert
Attributes inherited from Function
#args, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
aligned
invertable?
Methods inherited from Function
aligned, inherited, #initialize, invertable?, #prepend, #read
Class Method Details
.params ⇒ Object
41
42
43
|
# File 'lib/ciphr/functions/base_radix.rb', line 41
def self.params
[:input]
end
|
.variants ⇒ Object
37
38
39
|
# File 'lib/ciphr/functions/base_radix.rb', line 37
def self.variants
[[['b8','base8','oct','octal'], {}]]
end
|
Instance Method Details
#apply ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/ciphr/functions/base_radix.rb', line 45
def apply
input = @args[0]
if !invert
Proc.new do
chunk = input.read(3)
chunk = chunk && chunk + "\x00"*(3-chunk.size) chunk && chunk.unpack("B*")[0].bytes.to_a.each_slice(3).to_a.map{|a|a.pack("c*").to_i(2).to_s(8)}.join
end
else
Proc.new do
chunk = input.read(8)
chunk = chunk && chunk + "0"*(8-chunk.size) chunk && chunk.unpack("aaaaaaaa").map{|o| o.to_i.to_s(2).rjust(3,"0")}.join.unpack("a8a8a8").map{|b| b.to_i(2)}.pack("C*")
end
end
end
|