| 1 | package Proquint; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Exporter::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 8 | 1 | our @ISA = 'Exporter::Tiny'; | |||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = (qw/uint32proquint proquint32uint hex2proquint proquint2hex/); | |||||||||||||||||||||||||||
| 10 | 1 | our @EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | my @UINT_TO_CONSONANT = (qw/ b d f g h j k l m n p r s t v z /); | |||||||||||||||||||||||||||
| 13 | 1 | my @UINT_TO_VOWEL = (qw/ a i o u /); | |||||||||||||||||||||||||||
| 14 | 1 | my $CHARS_PER_CHUNK = 5; | |||||||||||||||||||||||||||
| 15 | 1 | my $MASK_LAST2 = 0x3; | |||||||||||||||||||||||||||
| 16 | 1 | my $MASK_LAST4 = 0xF; | |||||||||||||||||||||||||||
| 17 | 1 | my $SEPARATOR = '-'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my %CONSONANT_TO_UINT = do { | |||||||||||||||||||||||||||
| 20 | 1 | my $i = 0; | |||||||||||||||||||||||||||
| 21 | 1 | map { $_ => $i++ } @UINT_TO_CONSONANT; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | my %VOWEL_TO_UINT = do { | |||||||||||||||||||||||||||
| 25 | 1 | my $i = 0; | |||||||||||||||||||||||||||
| 26 | 1 | map { $_ => $i++ } @UINT_TO_VOWEL; | |||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 7 | ▶ | sub _uint16_to_chunk { | ||||||||||||||||||||||||||
|
Subroutine
_uint16_to_chunk: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | my $in = shift // Carp::croak 'usage: _uint16_to_chunk($INTEGER)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: _uint16_to_chunk(\$INTEGER)")
MC/DC0%0/1
shift() // Carp::croak("usage: _uint16_to_chunk(\$INTEGER)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 31 | 7 | my $out = ''; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | foreach my $i ( 1 .. $CHARS_PER_CHUNK ) { | |||||||||||||||||||||||||||
| 34 | 35 | ▶ | if ( $i & 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 21 | $out .= $UINT_TO_CONSONANT[ $in & $MASK_LAST4 ]; | |||||||||||||||||||||||||||
| 36 | 21 | $in >>= 4; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 14 | $out .= $UINT_TO_VOWEL[ $in & $MASK_LAST2 ]; | |||||||||||||||||||||||||||
| 40 | 14 | $in >>= 2; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 7 | scalar reverse $out; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # uint32proquint(0x7f000001) eq 'lusab-babad'; | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub uint32proquint { | ||||||||||||||||||||||||||
|
Subroutine
uint32proquint: called CC=5 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $in = shift // Carp::croak 'usage: uint32proquint($INTEGER)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: uint32proquint(\$INTEGER)")
MC/DC0%0/1
shift() // Carp::croak("usage: uint32proquint(\$INTEGER)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | my $sep = shift // $SEPARATOR; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() // $SEPARATOR
MC/DC0%0/2
shift() // $SEPARATOR
shift()
$SEPARATOR
Truth table33%1/3
A // B
A= shift()B= $SEPARATOR
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | Carp::croak('input out of range 0-0xFFFFFFFF') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$in < 0 or $in > 4294967295
MC/DC0%0/2
$in < 0 or $in > 4294967295
$in < 0
$in > 4294967295
Truth table33%1/3
A or B
A= $in < 0B= $in > 4294967295
| |||||||||||||||||||||||||||||
| 52 | if $in < 0 or $in > 0xffffffff; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | _uint16_to_chunk( $in >> 16 ) . $sep . _uint16_to_chunk($in); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | ▶ | sub _chunk_to_uint16 { | ||||||||||||||||||||||||||
|
Subroutine
_chunk_to_uint16: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||
| 58 | 7 | ▶ | my $in = shift // Carp::croak 'usage: _chunk_to_uint16($INTEGER)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: _chunk_to_uint16(\$INTEGER)")
MC/DC0%0/1
shift() // Carp::croak("usage: _chunk_to_uint16(\$INTEGER)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 7 | ▶ | Carp::croak 'invalid chunk: ' . $in unless length($in) == $CHARS_PER_CHUNK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 7 | my $res = 0; | |||||||||||||||||||||||||||
| 63 | 7 | foreach my $c ( split //, $in ) { | |||||||||||||||||||||||||||
| 64 | 35 | ▶ | if ( exists $CONSONANT_TO_UINT{$c} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 65 | 21 | $res <<= 4; | |||||||||||||||||||||||||||
| 66 | 21 | $res += $CONSONANT_TO_UINT{$c}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | elsif ( exists $VOWEL_TO_UINT{$c} ) { | ||||||||||||||||||||||||||||
| 69 | 14 | $res <<= 2; | |||||||||||||||||||||||||||
| 70 | 14 | $res += $VOWEL_TO_UINT{$c}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | Carp::croak 'invalid quint char: ' . $c; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 7 | $res; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # proquint32uint('lusab-babad') == 0x7f000001; | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub proquint32uint { | ||||||||||||||||||||||||||
|
Subroutine
proquint32uint: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my $in = shift // Carp::croak 'usage: proquint32uint($QUINT)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: proquint32uint(\$QUINT)")
MC/DC0%0/1
shift() // Carp::croak("usage: proquint32uint(\$QUINT)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | my $sep = shift // $SEPARATOR; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() // $SEPARATOR
MC/DC0%0/2
shift() // $SEPARATOR
shift()
$SEPARATOR
Truth table33%1/3
A // B
A= shift()B= $SEPARATOR
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | $in =~ s/$sep//g; | |||||||||||||||||||||||||||
| 86 | 1 | ▶ | Carp::croak 'invalid quint: ' . $in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | unless not length($in) % $CHARS_PER_CHUNK; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | my @chunks = $in =~ m/(.{$CHARS_PER_CHUNK})/gx; | |||||||||||||||||||||||||||
| 90 | 1 | ▶ | Carp::croak 'invalid quint: ' . $in unless @chunks == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | my $out = _chunk_to_uint16( $chunks[0] ); | |||||||||||||||||||||||||||
| 93 | 1 | $out <<= 16; | |||||||||||||||||||||||||||
| 94 | 1 | $out += _chunk_to_uint16( $chunks[1] ); | |||||||||||||||||||||||||||
| 95 | 1 | $out; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # hex2proquint('7f00001') eq 'lusab-babad' | ||||||||||||||||||||||||||||
| 99 | 2 | ▶ | sub hex2proquint { | ||||||||||||||||||||||||||
|
Subroutine
hex2proquint: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | my $in = shift // Carp::croak 'usage: hex2proquint($HEXIDECIMAL)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: hex2proquint(\$HEXIDECIMAL)")
MC/DC0%0/1
shift() // Carp::croak("usage: hex2proquint(\$HEXIDECIMAL)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my $sep = shift // $SEPARATOR; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() // $SEPARATOR
MC/DC0%0/2
shift() // $SEPARATOR
shift()
$SEPARATOR
Truth table33%1/3
A // B
A= shift()B= $SEPARATOR
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | $in =~ s/^0[xX]//; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | Carp::croak 'input must be multiple of 4-characters' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | unless not length($in) % 4; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | join( $sep, | ||||||||||||||||||||||||||||
| 109 | 2 | map { _uint16_to_chunk( hex( '0x' . $_ ) ) } $in =~ m/(.{4})/g ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # proquint2hex('lusab-babad') eq '7f000001'; | ||||||||||||||||||||||||||||
| 113 | 2 | ▶ | sub proquint2hex { | ||||||||||||||||||||||||||
|
Subroutine
proquint2hex: called CC=5 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 2 | ▶ | my $in = shift // Carp::croak 'usage: proquint2hex($QUINT)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // Carp::croak("usage: proquint2hex(\$QUINT)")
MC/DC0%0/1
shift() // Carp::croak("usage: proquint2hex(\$QUINT)")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | my $sep = shift // $SEPARATOR; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() // $SEPARATOR
MC/DC0%0/2
shift() // $SEPARATOR
shift()
$SEPARATOR
Truth table33%1/3
A // B
A= shift()B= $SEPARATOR
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | $in =~ s/$sep//g; | |||||||||||||||||||||||||||
| 118 | 2 | ▶ | Carp::croak 'invalid quint: ' . $in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | unless not length($in) % $CHARS_PER_CHUNK; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | my @chunks = $in =~ m/(.{$CHARS_PER_CHUNK})/g; | |||||||||||||||||||||||||||
| 122 | 2 | ▶ | Carp::croak 'invalid quint: ' . $in unless @chunks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | join( '', map { sprintf( '%04x', _chunk_to_uint16($_) ) } @chunks ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||