Sorry for double-post, it was too late for editing...
This is the function I made out of it:
For explain:
$bkz and $sn: Both part of the serial number of the ID card
$birth: Birth date
(YYMMTT format
)
$valid: How long is the ID card valid
(Again YYMMTT
)
$perso: The complete number, incl. checksums of the three components and global checksum
$perso_str:$perso in format of real ID card
print "Bitte BKZ eingeben(4 Stellen)\n";
$bkz=<stdin>;
chomp($bkz);
print "Bitte Seriennummer eingeben(5 Stellen)\n";
$sn=<stdin>;
chomp($sn);
$sn_c=$bkz . $sn;
$sn_c .= checkSum($sn_c);
$perso = $sn_c;
$perso_str=$sn_c . "D<<";
print "Bitte Geburtsdatum eingeben(JJMMTT)\n";
$birth=<stdin>;
chomp($birth);
$birth .= checkSum($birth);
$perso .= $birth;
$perso_str .= $birth . "<";
print "Bitte Ablaufdatum eingeben(JJMMTT)\n";
$valid=<stdin>;
chomp($valid);
$valid .= checkSum($valid);
$perso .= $valid;
$perso_str .= $valid . "<<<<<<<";
$perso_str .=checkSum($perso);
$perso .=checkSum($perso);
print "Ihre Personalausweis-Nummer: \n$perso_str \nBitte drücken Sie RETURN";
$dummy=<stdin>;
chomp($dummy);
sub checkSum
{
local $number=shift @_;
local @multipliers =(7,3,1);
local $i;
local $sum;
local @num=unpack("A1" x length($number),$number);
for($i = 0; $i < length($number); $i++
{
#print "$i... ($num[$i] * $multipliers[($i%3)])";
$sum += $num[$i] * $multipliers[$i%3];
}
return $sum % 10;
}
Oh...for what this is useful: You give the program some dates, and it generates vaild ID card numbers vor Germany
(AFAIK for other EU countries too
).