#!/usr/bin/perl # test_crc.pl - Don Yang (uguu.org) # # 03/17/04 use strict; my (@table, @text); $ARGV[1] && (srand $ARGV[1]); die "$0 \n" unless( $ARGV[0] ); sub InitTable { my ($i, $j, $crc); $#table = 255; for($i = 0; ($crc = $i) < 256; $table[$i++] = $crc) { for($j = 8; $j > 0; $j--) { $crc = ($crc >> 1) ^ (($crc & 1) ? 0xedb88320 : 0); } } } sub CRC { my ($str) = @_; my ($crc); for($crc = 0xffffffff; length($str) > 0; $str = substr($str, 1)) { $crc = (($crc >> 8) & 0xffffff) ^ $table[($crc ^ ord($str)) & 255]; } return $crc; } sub CreateStrings { my ($o, $i, $j, $s, $c); @text = (); for($o = 0; $o < 16;) { $s = ''; for($j = 0; $j < 1024; $j++) { $s .= ('a'..'z', 'A'..'Z', '0'..'9')[int(rand 62)]; } $c = CRC($s); for($j = 0; $j < 4; $j++) { $i = chr($c & 0xff); if( $i eq "\r" || $i eq "\n" ) { $s = ''; last; } $s .= $i; $c >>= 8; } if( length($s) ) { push @text, $s . "\n"; $o++; } } } sub main { my ($i); local (*FILE); InitTable(); CreateStrings(); open FILE, "> $ARGV[0]" or die $!; for($i = 0; $i < 1024; $i++) { print FILE $text[int(rand 10)]; } close FILE; } main();