(file) Return to encode-dc.pl CVS log (file) (dir) Up to [venge] / src / modfs

File: [venge] / src / modfs / encode-dc.pl (download)
Revision: 1.1.1.1 (vendor branch), Wed Feb 2 07:48:34 2000 UTC (10 years, 7 months ago) by graydon
Branch: vengeance, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
importing

#!/usr/bin/perl
use Math::BigInt;
use SHA;

my $default_prime_bit_length = 24;
my $default_num_of_primes = 10;
my $default_block_bit_length = 1024;

my @primes = primes(shift @ARGV || $default_prime_bit_length);
my $sha = new SHA;
my $buf;
my $i = 0;
my $command_string;

print "(primes:" . join(':', @primes) . ")\n";
while ($len = read STDIN, $buf, $default_block_bit_length) {
  $i++;
  my $block = join('', unpack("I*", $buf));
  $command_string .= " $block sa ";
  my $hash = $sha->hexhash($block);
  map { $command_string .= " la $_ % " } @primes;
  $command_string .= " n " . (" [:] n n " x ($#primes - 1));
  print "(block:$i:$len:$hash)\n(";
  dc(\$command_string);
  print ")\n";
}

#print "running $command_string\n\n\n";

sub dc {
  my $cmd = shift;
  open DC, "|dc";
  print DC $$cmd;
  close DC;    
}

sub primes {
  my $stop = shift;
  my $start = $stop - 1;
  open PRIMES, "echo '2 $stop ^ [ ] 2 $start ^ n n n' | dc | xargs primes | tail -n $default_num_of_primes |";
  my @primes = <PRIMES>;
  close PRIMES;
  chomp @primes;
  return @primes;
}

graydon hoare
Powered by
ViewCVS 0.9.2