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

Version Path
emonti-rbkb-0.6.2.1 lib/rbkb/cli/xor.rb
emonti-rbkb-0.6.6 lib/rbkb/cli/xor.rb
emonti-rbkb-0.6.7 lib/rbkb/cli/xor.rb
emonti-rbkb-0.6.8 lib/rbkb/cli/xor.rb
emonti-rbkb-0.6.9.1 lib/rbkb/cli/xor.rb
emonti-rbkb-0.6.9 lib/rbkb/cli/xor.rb
rbkb-0.7.2 lib/rbkb/cli/xor.rb
rbkb-0.7.1 lib/rbkb/cli/xor.rb
rbkb-0.7.0 lib/rbkb/cli/xor.rb
rbkb-0.6.12 lib/rbkb/cli/xor.rb
rbkb-0.6.11 lib/rbkb/cli/xor.rb
rbkb-0.6.10 lib/rbkb/cli/xor.rb