class Rbkb::Cli::Xor
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).
Public Instance Methods
go(*args)
click to toggle source
Calls superclass method
Rbkb::Cli::Executable#go
# 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()
click to toggle source
Calls superclass method
Rbkb::Cli::Executable#make_parser
# File lib/rbkb/cli/xor.rb, line 9 def make_parser() super() add_std_file_opt(:indat) arg = @oparse arg.banner += " -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 return arg end
parse(*args)
click to toggle source
Calls superclass method
Rbkb::Cli::Executable#parse
# 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