Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub parse {
- my ($sequence) = @_;
- $sequence =~ s/[^0123]//g; # leave just digits
- $sequence =~ s/1032$//; # remove identifier at the end, if any
- die "Sequence should contain 8 or 12 quaternary digits" unless $sequence =~ m/^([0123]{4})([0123]{4})$/;
- my $byte = quad2dec($1);
- return -1 unless ($byte & 192) == 192; # two higer bits must be set
- #print "{$byte}";
- $byte &= 63; # use 6 leftmost bits
- my $checksum = $checksums[$byte];
- return -1 unless ($checksum == $2); # checksums must match
- #print "<$1><$2>=<$byte><$checksum>\n";
- return $byte;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement