Sha256: ccff5606721b7ecbb003c2b215dd9ff14328ff42c0e3a7d6ff3d177c258af702
Contents?: true
Size: 1.53 KB
Versions: 3
Compression:
Stored size: 1.53 KB
Contents
#!/usr/bin/env ruby # (emonti at matasano) Matasano Security LLC # # crc32.rb : returns a crc32 checksum in hex from stdin or a file # # Usage: crc32 [options] # -h, --help Show this message # -v, --version Show version and exit # -f, --file FILENAME Input from FILENAME # -r, --range=START[:END] Start and optional end range # -x, --hexrange=START[:END] same, but in hex require 'rbkb' require 'rbkb/command_line' include RBkB::CommandLine OPTS = {:first => 0, :last => -1} arg = bkb_stdargs(nil, OPTS) arg = bkb_inputargs(arg, OPTS) arg.on("-r", "--range=START[:END]", "Start and optional end range") do |r| raise "-x and -r are mutually exclusive" if OPTS[:first] unless m=/^(-?[0-9]+)(?::(-?[0-9]+))?$/.match(r) raise "invalid range #{r.inspect}" end OPTS[:first] = $1.to_i OPTS[:last] = $2.to_i if $2 end arg.on("-x", "--hexrange=START[:END]", "same, but in hex") do |r| raise "-x and -r are mutually exclusive" if OPTS[:first] unless m=/^(-?[0-9a-f]+)(?::(-?[0-9a-f]+))?$/i.match(r) raise "invalid range #{r.inspect}" end OPTS[:first]=($1[0,1] == '-')? ($1[1..-1]).hex_to_num * -1 : $1.hex_to_num if $2 OPTS[:last]=($2[0,1] == '-')? ($2[1..-1]).hex_to_num * -1 : $2.hex_to_num end end begin arg.parse! raise "bad arguments #{ARGV.join(" ").inspect}" unless (ARGV.length == 0) OPTS[:indat] ||= STDIN.read() puts OPTS[:indat][ OPTS[:first] .. OPTS[:last] ].crc32.to_hex rescue bail "Error: #{$!}\n#{arg}" end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
emonti-rbkb-0.6.1.1 | bin/crc32 |
emonti-rbkb-0.6.1.2 | bin/crc32 |
emonti-rbkb-0.6.1.3 | bin/crc32 |