Sha256: c13a05ab5170b387412a167a4770b1e1f87b93c5f6438e65cb7ab5bcf861a6c7

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

#!/usr/bin/env ruby
# Author Eric Monti (emonti at matasano)
#
# repeating string xor
#
# Usage: xor [options] -k|-s <key> <data | stdin>
#     -h, --help                       Show this message
#     -v, --version                    Show version and exit
#     -f, --file FILENAME              Input from FILENAME
# 
#   Key options (one of the following is required):
#     -s, --strkey STRING              xor against bare STRING
#     -x, --hexkey HEXSTR              xor against decoded HEXSTR
# 

require 'rbkb'
require 'rbkb/command_line'

include RBkB::CommandLine

#-------------------------------------------------------------------------------
# Init options and arg parsing
OPTS = {}
arg = bkb_stdargs(nil, OPTS)
arg = bkb_inputargs(arg, OPTS)

arg.banner += " -k|-s <key> <data | stdin>"

#------------------------------------------------------------------------------
# Add local options
arg.separator ""
arg.separator "  Key options (one of the following is required):"

arg.on("-s", "--strkey STRING", "xor against bare 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 decoded 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

#------------------------------------------------------------------------------
# Parse arguments
arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"

bail "You must specify a key with -s or -x\n#{arg}" unless OPTS[:key]

OPTS[:indat] ||= ARGV.shift

if ARGV.length != 0
    bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
end

OPTS[:indat] ||= STDIN.read()

STDOUT.write OPTS[:indat].xor(OPTS[:key])

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
emonti-rbkb-0.6.1.1 bin/xor
emonti-rbkb-0.6.1.2 bin/xor
emonti-rbkb-0.6.1.3 bin/xor