#!/usr/bin/perl # THIS CODE IS BUGGY AND SLOW # It is only here as a "proof of concept" # Download the real stuff at http://www.iguana.be/~stef/ # written by stef@iguana.be, June 2001 # based on the bommanews specs # this is very SLOW! # You will need to install Bit::Vector for this to work # usage: $0 file.bn # TODO: CLEANUP this mess use Bit::Vector; use FileHandle; @chunk; $v224 = Bit::Vector->new_Dec(328, 224); $t = Bit::Vector->new(328); $x = Bit::Vector->new(320); for (0..223) { $bv[$_] = Bit::Vector->new_Dec(328, $_); } while (<>) { /^<>$/ && do { $filename = $1; $size = $2; print "$filename $size\n"; $file = new FileHandle ">$filename" or die; next; }; $line = $_; $l = length($line); $lines++; if ($l % 41 != 1) { print "line lenght: ", length($line), " on line $lines\n"; if ($l % 41 == 0) { print "prepending .\n"; $line = "." . $line; } } @line = split('', $line); for $char (@line) { $ch = ord($char); if ($ch > 31) { unshift(@chunk, $ch - 32 ); } if ($#chunk == 40) { decode224(@chunk); $#chunk = -1; } } if ($#chunk != -1) { print "Line $lines, filling $#chunk .. 39\n"; for ($#chunk .. 39) { unshift(@chunk, 0); } print "chunk now $#chunk\n"; decode224(@chunk); $#chunk = -1; } } $file->truncate($size); $file->close; sub decode224 { $t->from_Dec(shift @_); for my $c (@_) { $t->Multiply($t, $v224); $carry = $t->add($t, $bv[$c], 0); } $x->Interval_Copy($t,0,0,320); print $file $x->Block_Read(); }