Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Created November 16, 2015 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpavlin/9b370bf60e26fc66ce4a to your computer and use it in GitHub Desktop.
Save dpavlin/9b370bf60e26fc66ce4a to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# http://www.regos.hr/UserDocsImages/KONTROLA%20OIB-a.pdf
my $oib = 69435151530;
my ($nr,$ck) = ( substr($oib,0,10), substr($oib,-1,1) );
print "$oib -> $nr $ck\n";
my $test = $1 if $oib =~ s/^(\d)//;
print "b $test\t";
$test += 10;
while ( 1 ) {
print "c $test\t";
$test = $test % 10;
$test = 10 if $test == 0;
print "d $test\t";
$test *= 2;
print "e $test\t";
$test = $test % 11;
print "f $test\t";
last if ! $oib;
$test += $1 if $oib =~ s/^(\d)//;
print "\nb $1\t";
}
$test = 11 - $test;
$test = 0 if $test == 10;
print "\n$ck ? ",$test," ", $ck == $test ? "ok" : "error","\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment