Class: Rbkb::Cli::Xor
- Inherits:
-
Executable
- Object
- Executable
- Rbkb::Cli::Xor
- Defined in:
- lib/rbkb/cli/xor.rb
Overview
Copyright 2009 emonti at matasano.com See README.rdoc for license information
Repeating string xor. Takes input from a string, stdin, or a file (-f).
Instance Attribute Summary
Attributes inherited from Executable
#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout
Instance Method Summary collapse
Methods inherited from Executable
#bail, #bail_args, #exit, #initialize, run
Constructor Details
This class inherits a constructor from Rbkb::Cli::Executable
Instance Method Details
#go(*args) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rbkb/cli/xor.rb', line 36 def go(*args) super(*args) @opts[:indat] ||= @stdin.read @stdout << @opts[:indat].xor(@opts[:key]) self.exit(0) end |
#make_parser ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbkb/cli/xor.rb', line 9 def make_parser super() add_std_file_opt(:indat) arg = @oparse arg. += ' -k|-s <key> <data | stdin>' arg.separator ' Key options (you must specify one of the following):' arg.on('-s', '--strkey STRING', 'xor against STRING') do |s| bail 'only one key option can be specified with -s or -x' if @opts[:key] @opts[:key] = s end arg.on('-x', '--hexkey HEXSTR', 'xor against binary HEXSTR') do |x| bail 'only one key option can be specified with -s or -x' if @opts[:key] x.sub!(/^0[xX]/, '') bail 'Unable to parse hex string' unless @opts[:key] = x.unhexify end arg end |
#parse(*args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rbkb/cli/xor.rb', line 29 def parse(*args) super(*args) bail("You must specify a key with -s or -x\n#{@oparse}") unless @opts[:key] parse_string_argument(:indat) parse_catchall end |