#! /usr/bin/perl

$len = shift || 32;
$op = shift || "+";

sub r {
  my $l = shift || $len;
  my $i;
  my $s;
  for ($i = 0; $i < $l; $i++) {
    my $x = rand(256);
    $s .= sprintf("%02x", $x);
  }
  return $s;
}

$| = 1;
open(BC, "|bc | tr A-Z a-z") or die;
print BC "obase=16\nibase=16\n";
$x = r();
if ($op eq "<<" || $op eq ">>") {
  $y = int(rand($len * 4)) + int(rand($len * 4));
  $op = ($op eq "<<" ? "*" : "/");
  $z = sprintf("%x", $y);
  print "$x $y\n";
  print BC "\U$x $op (2^$z)\n";
} elsif ($op eq "/") {
  $ylen = int(rand($len)) + 1;
  $y = r($ylen);
  print "$x\n$y\n";
  print BC "\U$x / $y\n$x % $y\n";
} elsif ($op eq "2") {
  print "$x\n";
  print BC "\U$x * $x\n";
} else {
  $y = r();
  print "$x\n$y\n";
  print BC "\U$x $op $y\n";
}
close(BC);
