#!/usr/bin/perl -w use File::Basename(qw(basename)); $HASH_NUM = 5; if ($#ARGV != 2-1 && $#ARGV != 3-1) { print "Usage: ".basename($0)." HASHDATA(.dll) UNIQKEYLIST(.txt) HASHNUM\n"; print "Output 2 files for protection type 01.\n"; print "HASHDATA(.dll): binary file filled by hash of uniq key 2\n"; print "UNIQKEYLIST(.txt): text file lists uniq keys\n"; print "HASHNUM: hash number will be generated(def=$HASH_NUM)\n"; exit 1; } if ($#ARGV == 3-1) { $HASH_NUM = int($ARGV[2]); if ($HASH_NUM == 0) { die "Wrong HASHNUM($ARGV[3])"; } } # open files $HASHDATAFILE = $ARGV[0]; $UNIQKEYLIST = $ARGV[1]; open HASHDATAFILE, ">$HASHDATAFILE" or die "Open error: $HASHDATAFILE($!)"; open UNIQKEYLIST, ">$UNIQKEYLIST" or die "Open error: $UNIQKEYLIST($!)"; binmode HASHDATAFILE; # print header for UNIQKEYLIST ($sec,$min,$hour,$day,$month,$year,$tmp) = localtime(time); $tmp++; # avoid worning of "unused value $tmp" print UNIQKEYLIST "OutputDate : ".sprintf("%d/%02d/%02d %02d:%02d:%02d\n", $year+1900, $month+1, $day, $hour, $min, $sec); print UNIQKEYLIST "HASHDATAFILE: $HASHDATAFILE\n"; print UNIQKEYLIST "UNIQKEYLIST : $UNIQKEYLIST\n"; print UNIQKEYLIST "\n"; print UNIQKEYLIST "=========== uniq key ===========\n"; # create hash1 and hash2, write them onto each files use Digest::MD5 qw(md5 md5_hex); @keyary = (); for ($i = 0; $i < $HASH_NUM; $i++) { # for generating unique key1/key2 do { $key = md5_hex(rand($HASH_NUM*100000)); } while (scalar(grep(/^$key$/, @keyary)) > 0); $keyary[$i] = $key; print UNIQKEYLIST "$key\n"; print HASHDATAFILE md5($key); } print UNIQKEYLIST "\nmd5sum of $HASHDATAFILE = ".`md5sum $HASHDATAFILE`."\n"; # close all files close UNIQKEYLIST; close HASHDATAFILE;