ciphr 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +6 -3
- data/LICENSE.txt +22 -22
- data/README.md +13 -4
- data/Rakefile +7 -7
- data/TODO +320 -320
- data/bin/ciphr +3 -1
- data/ciphr.gemspec +0 -0
- data/lib/ciphr.rb +2 -0
- data/lib/ciphr/function_registry.rb +0 -0
- data/lib/ciphr/functions.rb +63 -62
- data/lib/ciphr/functions/ascii.rb +25 -0
- data/lib/ciphr/functions/base_radix.rb +205 -205
- data/lib/ciphr/functions/bitwise.rb +80 -80
- data/lib/ciphr/functions/crypto.rb +42 -44
- data/lib/ciphr/functions/openssl.rb +104 -104
- data/lib/ciphr/functions/reader.rb +46 -44
- data/lib/ciphr/functions/simple.rb +121 -121
- data/lib/ciphr/functions/url.rb +38 -38
- data/lib/ciphr/functions/zlib.rb +95 -94
- data/lib/ciphr/parser.rb +0 -0
- data/lib/ciphr/stream.rb +49 -49
- data/lib/ciphr/version.rb +1 -1
- data/pkg/ciphr-0.0.3.gem +0 -0
- data/spec/ciphr_spec.rb +21 -21
- data/spec/functions_spec.rb +31 -31
- data/spec/randomizer_spec.rb +55 -55
- data/spec/spec_helper.rb +4 -4
- data/spec/stream_spec.rb +38 -38
- data/tests/output.r26.2.0.0.bin +0 -0
- data/tests/output.r26.2.1.1.bin +0 -0
- data/tests/output.r30.2.0.0.bin +0 -0
- data/tests/output.r30.2.1.1.bin +0 -0
- data/tests/output.r34.2.0.0.bin +0 -0
- data/tests/output.r34.2.1.1.bin +0 -0
- data/tests/testcase.r26.bin +0 -0
- data/tests/testcase.r30.bin +0 -0
- data/tests/testcase.r34.bin +0 -0
- metadata +5 -6
- data/pkg/ciphr-0.0.1.gem +0 -0
- data/pkg/ciphr-0.0.2.gem +0 -0
data/bin/ciphr
CHANGED
@@ -31,7 +31,9 @@ Slop.parse do
|
|
31
31
|
if opts[:'xargs-mode']
|
32
32
|
delim = opts['null'] ? "\x00" : "\n"
|
33
33
|
$stdin.each_line(delim) do |line|
|
34
|
-
|
34
|
+
io = StringIO.new(line.tr(delim,''))
|
35
|
+
io.bindmode
|
36
|
+
transformed = Ciphr::Transformer.new(io).apply(parsed)
|
35
37
|
$stdout.print transformed.read
|
36
38
|
puts if newline
|
37
39
|
end
|
data/ciphr.gemspec
CHANGED
File without changes
|
data/lib/ciphr.rb
CHANGED
File without changes
|
data/lib/ciphr/functions.rb
CHANGED
@@ -1,62 +1,63 @@
|
|
1
|
-
|
2
|
-
#require 'base32/crockford'
|
3
|
-
#require 'zbase32'
|
4
|
-
require_relative 'function_registry'
|
5
|
-
|
6
|
-
module Ciphr::Functions
|
7
|
-
class Function
|
8
|
-
def initialize(options, args)
|
9
|
-
@options = options
|
10
|
-
@args = args
|
11
|
-
@stream = Ciphr::Stream.new(self)
|
12
|
-
end
|
13
|
-
attr_accessor :options, :args #don't like that these are both writable, but c'est la vie
|
14
|
-
|
15
|
-
def self.variants
|
16
|
-
[]
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.inherited(subclass)
|
20
|
-
Ciphr::FunctionRegistry.global.register(subclass)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.params
|
24
|
-
[]
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.invertable?
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.aligned
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def read(*args)
|
36
|
-
@stream.read(*args)
|
37
|
-
end
|
38
|
-
|
39
|
-
def prepend(*args)
|
40
|
-
@stream.prepend(*args)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class InvertibleFunction < Function
|
45
|
-
@invert = false
|
46
|
-
attr_accessor :invert
|
47
|
-
|
48
|
-
def self.invertable?
|
49
|
-
true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
require_relative 'functions/openssl'
|
55
|
-
require_relative 'functions/base_radix'
|
56
|
-
require_relative 'functions/zlib'
|
57
|
-
require_relative 'functions/bitwise'
|
58
|
-
require_relative 'functions/reader'
|
59
|
-
require_relative 'functions/url'
|
60
|
-
require_relative 'functions/simple'
|
61
|
-
require_relative 'functions/crypto'
|
62
|
-
|
1
|
+
|
2
|
+
#require 'base32/crockford'
|
3
|
+
#require 'zbase32'
|
4
|
+
require_relative 'function_registry'
|
5
|
+
|
6
|
+
module Ciphr::Functions
|
7
|
+
class Function
|
8
|
+
def initialize(options, args)
|
9
|
+
@options = options
|
10
|
+
@args = args
|
11
|
+
@stream = Ciphr::Stream.new(self)
|
12
|
+
end
|
13
|
+
attr_accessor :options, :args #don't like that these are both writable, but c'est la vie
|
14
|
+
|
15
|
+
def self.variants
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.inherited(subclass)
|
20
|
+
Ciphr::FunctionRegistry.global.register(subclass)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.params
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.invertable?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.aligned
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def read(*args)
|
36
|
+
@stream.read(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def prepend(*args)
|
40
|
+
@stream.prepend(*args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class InvertibleFunction < Function
|
45
|
+
@invert = false
|
46
|
+
attr_accessor :invert
|
47
|
+
|
48
|
+
def self.invertable?
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
require_relative 'functions/openssl'
|
55
|
+
require_relative 'functions/base_radix'
|
56
|
+
require_relative 'functions/zlib'
|
57
|
+
require_relative 'functions/bitwise'
|
58
|
+
require_relative 'functions/reader'
|
59
|
+
require_relative 'functions/url'
|
60
|
+
require_relative 'functions/simple'
|
61
|
+
require_relative 'functions/crypto'
|
62
|
+
require_relative 'functions/ascii'
|
63
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Ciphr::Functions::Ascii
|
2
|
+
class Rot13 < Ciphr::Functions::InvertibleFunction
|
3
|
+
def apply
|
4
|
+
input = @args[0]
|
5
|
+
Proc.new do
|
6
|
+
inchunk = input.read(256)
|
7
|
+
if inchunk
|
8
|
+
inchunk.tr("A-Za-z", "N-ZA-Mn-za-m")
|
9
|
+
else
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.variants
|
16
|
+
[
|
17
|
+
['rot13', {}]
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.params
|
22
|
+
[:input]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,205 +1,205 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'base32'
|
3
|
-
|
4
|
-
module Ciphr::Functions::Base
|
5
|
-
class Base < Ciphr::Functions::InvertibleFunction
|
6
|
-
def self.aligned
|
7
|
-
:left
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Base2 < Base
|
12
|
-
def self.variants
|
13
|
-
[[['b2','base2', 'bin','binary'], {}]]
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.params
|
17
|
-
[:input]
|
18
|
-
end
|
19
|
-
|
20
|
-
def apply
|
21
|
-
input = @args[0]
|
22
|
-
if !invert
|
23
|
-
Proc.new do
|
24
|
-
chunk = input.read(1)
|
25
|
-
chunk && chunk.unpack("B*")[0]
|
26
|
-
end
|
27
|
-
else
|
28
|
-
Proc.new do
|
29
|
-
chunk = input.read(8)
|
30
|
-
chunk && [chunk].pack("B*")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class Base8 < Base
|
37
|
-
def self.variants
|
38
|
-
[[['b8','base8','oct','octal'], {}]]
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.params
|
42
|
-
[:input]
|
43
|
-
end
|
44
|
-
|
45
|
-
def apply
|
46
|
-
input = @args[0]
|
47
|
-
if !invert
|
48
|
-
Proc.new do
|
49
|
-
chunk = input.read(3)
|
50
|
-
chunk = chunk && chunk + "\x00"*(3-chunk.size) #pad
|
51
|
-
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
|
52
|
-
end
|
53
|
-
else
|
54
|
-
Proc.new do
|
55
|
-
chunk = input.read(8)
|
56
|
-
chunk = chunk && chunk + "0"*(8-chunk.size) #pad
|
57
|
-
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*")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Base16 < Base
|
64
|
-
def self.variants
|
65
|
-
[[['b16','base16','hex','hexidecimal'], {}]]
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.params
|
69
|
-
[:input]
|
70
|
-
end
|
71
|
-
|
72
|
-
def apply
|
73
|
-
input = @args[0]
|
74
|
-
if !invert
|
75
|
-
Proc.new do
|
76
|
-
chunk = input.read(1)
|
77
|
-
chunk && chunk.unpack("H*")[0]
|
78
|
-
end
|
79
|
-
else
|
80
|
-
Proc.new do
|
81
|
-
chunk = input.read(2)
|
82
|
-
chunk && [chunk].pack("H*")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
class Base32 < Base
|
90
|
-
def self.variants
|
91
|
-
[
|
92
|
-
[['b32','base32','b32-std','base32-std'], {:object => ::Base32 }]#,
|
93
|
-
#broken
|
94
|
-
#[['b32-crockford','base32-crockford'], {:object => ::Base32::Crockford }],
|
95
|
-
#[['b32-z','base32-z'], {:object => ZBase32.new }]
|
96
|
-
]
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.params
|
100
|
-
[:input]
|
101
|
-
end
|
102
|
-
|
103
|
-
def apply
|
104
|
-
input = @args[0]
|
105
|
-
if !invert
|
106
|
-
Proc.new do
|
107
|
-
chunk = input.read(5)
|
108
|
-
chunk && options[:object].encode(chunk)
|
109
|
-
end
|
110
|
-
else
|
111
|
-
Proc.new do
|
112
|
-
chunk = input.read(8)
|
113
|
-
chunk && options[:object].decode(chunk)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class Base64 < Base
|
120
|
-
def self.aligned
|
121
|
-
nil # preserves alignment
|
122
|
-
end
|
123
|
-
|
124
|
-
def apply
|
125
|
-
input = @args[0]
|
126
|
-
if !invert
|
127
|
-
Proc.new do
|
128
|
-
chunk = input.read(3)
|
129
|
-
chunk && ::Base64.encode64(chunk).gsub(/\s/,'').tr("+/", options[:chars][0,2]).tr("=", options[:chars][2,3])
|
130
|
-
end
|
131
|
-
else
|
132
|
-
Proc.new do
|
133
|
-
chunk = input.read(4)
|
134
|
-
chunk = chunk && chunk + "="*(4-chunk.size) #pad
|
135
|
-
chunk && ::Base64.decode64(chunk.tr(options[:chars][0,2],"+/").tr(options[:chars][2,3],"=").ljust(4,"="))
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def self.variants
|
141
|
-
chars = {"+"=>"p", "-"=>"h", "_"=>"u", ":"=>"c", "/"=>"s", "." => "d", "!"=>"x", "="=>"q"}
|
142
|
-
types = {"+/=" => ["std"], "+/" => "utf7", "+-" => "file", "-_" => "url", "._-" => "yui",
|
143
|
-
".-" => "xml-name", "_:" => "xml-id", "_-" => "prog-id-1", "._" => "prog-id-2", "!-" => "regex"}
|
144
|
-
variants = types.map{|c,n| [["b64","base64"].product([c.chars.map{|c| chars[c] }.join,n]).map{|a| a.join("-")}, {:chars => c}]}
|
145
|
-
std = variants.select{|v| v[0].include? "b64-std"}[0] #add short aliases for standard
|
146
|
-
std[0] = ["b64","base64"].concat(std[0])
|
147
|
-
variants
|
148
|
-
end
|
149
|
-
|
150
|
-
def self.params
|
151
|
-
[:input]
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
module Ciphr::Functions::Radix
|
158
|
-
|
159
|
-
|
160
|
-
class Radix < Ciphr::Functions::InvertibleFunction
|
161
|
-
def self.aligned
|
162
|
-
:right
|
163
|
-
end
|
164
|
-
|
165
|
-
def self.variants
|
166
|
-
(2..36).map{|r| [["r#{r}","rad#{r}","radix#{r}"], {:radix => r}]}
|
167
|
-
end
|
168
|
-
|
169
|
-
def self.params
|
170
|
-
[:input]
|
171
|
-
end
|
172
|
-
|
173
|
-
def apply
|
174
|
-
radix = options[:radix]
|
175
|
-
input = @args[0]
|
176
|
-
if !invert
|
177
|
-
num = 0
|
178
|
-
while chunk = input.read(1)
|
179
|
-
num = (num << 8) + chunk.bytes.to_a[0]
|
180
|
-
end
|
181
|
-
Proc.new do
|
182
|
-
begin
|
183
|
-
num && num.to_s(radix)
|
184
|
-
ensure
|
185
|
-
num = nil
|
186
|
-
end
|
187
|
-
end
|
188
|
-
else
|
189
|
-
num = input.read().to_i(radix)
|
190
|
-
bytes = []
|
191
|
-
while num > 0
|
192
|
-
bytes.unshift(num & 0xff)
|
193
|
-
num = num >> 8
|
194
|
-
end
|
195
|
-
Proc.new do
|
196
|
-
begin
|
197
|
-
bytes && bytes.pack("c*")
|
198
|
-
ensure
|
199
|
-
bytes = nil
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
1
|
+
require 'base64'
|
2
|
+
require 'base32'
|
3
|
+
|
4
|
+
module Ciphr::Functions::Base
|
5
|
+
class Base < Ciphr::Functions::InvertibleFunction
|
6
|
+
def self.aligned
|
7
|
+
:left
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Base2 < Base
|
12
|
+
def self.variants
|
13
|
+
[[['b2','base2', 'bin','binary'], {}]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.params
|
17
|
+
[:input]
|
18
|
+
end
|
19
|
+
|
20
|
+
def apply
|
21
|
+
input = @args[0]
|
22
|
+
if !invert
|
23
|
+
Proc.new do
|
24
|
+
chunk = input.read(1)
|
25
|
+
chunk && chunk.unpack("B*")[0]
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Proc.new do
|
29
|
+
chunk = input.read(8)
|
30
|
+
chunk && [chunk].pack("B*")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Base8 < Base
|
37
|
+
def self.variants
|
38
|
+
[[['b8','base8','oct','octal'], {}]]
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.params
|
42
|
+
[:input]
|
43
|
+
end
|
44
|
+
|
45
|
+
def apply
|
46
|
+
input = @args[0]
|
47
|
+
if !invert
|
48
|
+
Proc.new do
|
49
|
+
chunk = input.read(3)
|
50
|
+
chunk = chunk && chunk + "\x00"*(3-chunk.size) #pad
|
51
|
+
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
|
52
|
+
end
|
53
|
+
else
|
54
|
+
Proc.new do
|
55
|
+
chunk = input.read(8)
|
56
|
+
chunk = chunk && chunk + "0"*(8-chunk.size) #pad
|
57
|
+
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*")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Base16 < Base
|
64
|
+
def self.variants
|
65
|
+
[[['b16','base16','hex','hexidecimal'], {}]]
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.params
|
69
|
+
[:input]
|
70
|
+
end
|
71
|
+
|
72
|
+
def apply
|
73
|
+
input = @args[0]
|
74
|
+
if !invert
|
75
|
+
Proc.new do
|
76
|
+
chunk = input.read(1)
|
77
|
+
chunk && chunk.unpack("H*")[0]
|
78
|
+
end
|
79
|
+
else
|
80
|
+
Proc.new do
|
81
|
+
chunk = input.read(2)
|
82
|
+
chunk && [chunk].pack("H*")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
class Base32 < Base
|
90
|
+
def self.variants
|
91
|
+
[
|
92
|
+
[['b32','base32','b32-std','base32-std'], {:object => ::Base32 }]#,
|
93
|
+
#broken
|
94
|
+
#[['b32-crockford','base32-crockford'], {:object => ::Base32::Crockford }],
|
95
|
+
#[['b32-z','base32-z'], {:object => ZBase32.new }]
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.params
|
100
|
+
[:input]
|
101
|
+
end
|
102
|
+
|
103
|
+
def apply
|
104
|
+
input = @args[0]
|
105
|
+
if !invert
|
106
|
+
Proc.new do
|
107
|
+
chunk = input.read(5)
|
108
|
+
chunk && options[:object].encode(chunk)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
Proc.new do
|
112
|
+
chunk = input.read(8)
|
113
|
+
chunk && options[:object].decode(chunk)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Base64 < Base
|
120
|
+
def self.aligned
|
121
|
+
nil # preserves alignment
|
122
|
+
end
|
123
|
+
|
124
|
+
def apply
|
125
|
+
input = @args[0]
|
126
|
+
if !invert
|
127
|
+
Proc.new do
|
128
|
+
chunk = input.read(3)
|
129
|
+
chunk && ::Base64.encode64(chunk).gsub(/\s/,'').tr("+/", options[:chars][0,2]).tr("=", options[:chars][2,3])
|
130
|
+
end
|
131
|
+
else
|
132
|
+
Proc.new do
|
133
|
+
chunk = input.read(4)
|
134
|
+
chunk = chunk && chunk + "="*(4-chunk.size) #pad
|
135
|
+
chunk && ::Base64.decode64(chunk.tr(options[:chars][0,2],"+/").tr(options[:chars][2,3],"=").ljust(4,"="))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.variants
|
141
|
+
chars = {"+"=>"p", "-"=>"h", "_"=>"u", ":"=>"c", "/"=>"s", "." => "d", "!"=>"x", "="=>"q"}
|
142
|
+
types = {"+/=" => ["std"], "+/" => "utf7", "+-" => "file", "-_" => "url", "._-" => "yui",
|
143
|
+
".-" => "xml-name", "_:" => "xml-id", "_-" => "prog-id-1", "._" => "prog-id-2", "!-" => "regex"}
|
144
|
+
variants = types.map{|c,n| [["b64","base64"].product([c.chars.map{|c| chars[c] }.join,n]).map{|a| a.join("-")}, {:chars => c}]}
|
145
|
+
std = variants.select{|v| v[0].include? "b64-std"}[0] #add short aliases for standard
|
146
|
+
std[0] = ["b64","base64"].concat(std[0])
|
147
|
+
variants
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.params
|
151
|
+
[:input]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
module Ciphr::Functions::Radix
|
158
|
+
|
159
|
+
|
160
|
+
class Radix < Ciphr::Functions::InvertibleFunction
|
161
|
+
def self.aligned
|
162
|
+
:right
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.variants
|
166
|
+
(2..36).map{|r| [["r#{r}","rad#{r}","radix#{r}"], {:radix => r}]}
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.params
|
170
|
+
[:input]
|
171
|
+
end
|
172
|
+
|
173
|
+
def apply
|
174
|
+
radix = options[:radix]
|
175
|
+
input = @args[0]
|
176
|
+
if !invert
|
177
|
+
num = 0
|
178
|
+
while chunk = input.read(1)
|
179
|
+
num = (num << 8) + chunk.bytes.to_a[0]
|
180
|
+
end
|
181
|
+
Proc.new do
|
182
|
+
begin
|
183
|
+
num && num.to_s(radix)
|
184
|
+
ensure
|
185
|
+
num = nil
|
186
|
+
end
|
187
|
+
end
|
188
|
+
else
|
189
|
+
num = input.read().to_i(radix)
|
190
|
+
bytes = []
|
191
|
+
while num > 0
|
192
|
+
bytes.unshift(num & 0xff)
|
193
|
+
num = num >> 8
|
194
|
+
end
|
195
|
+
Proc.new do
|
196
|
+
begin
|
197
|
+
bytes && bytes.pack("c*")
|
198
|
+
ensure
|
199
|
+
bytes = nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|