Sha256: 32ce35c2ccf7f196690fa0fbf788a3a0fe54a9b1496f65e9c658139ef6bd7e5f
Contents?: true
Size: 1.2 KB
Versions: 12
Compression:
Stored size: 1.2 KB
Contents
#!/usr/bin/env ruby require 'rbkb/cli' # 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). class Rbkb::Cli::Xor < Rbkb::Cli::Executable 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 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 def go(*args) super(*args) @opts[:indat] ||= @stdin.read @stdout << @opts[:indat].xor(@opts[:key]) self.exit(0) end end
Version data entries
12 entries across 12 versions & 2 rubygems