Advertisement
FrayxRulez

Untitled

Aug 13th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. sub parse {
  2. my ($sequence) = @_;
  3. $sequence =~ s/[^0123]//g; # leave just digits
  4. $sequence =~ s/1032$//; # remove identifier at the end, if any
  5. die "Sequence should contain 8 or 12 quaternary digits" unless $sequence =~ m/^([0123]{4})([0123]{4})$/;
  6.  
  7. my $byte = quad2dec($1);
  8. return -1 unless ($byte & 192) == 192; # two higer bits must be set
  9. #print "{$byte}";
  10.  
  11. $byte &= 63; # use 6 leftmost bits
  12. my $checksum = $checksums[$byte];
  13. return -1 unless ($checksum == $2); # checksums must match
  14.  
  15. #print "<$1><$2>=<$byte><$checksum>\n";
  16.  
  17. return $byte;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement