File Coverage

blib/lib/PGP/Words/Tiny.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 8 87.5
condition n/a
subroutine 9 9 100.0
pod 4 4 100.0
total 49 50 98.0


line stmt bran cond sub pod time code
1 1     1   23690 use 5.006;
  1         3  
  1         40  
2 1     1   6 use strict;
  1         1  
  1         40  
3 1     1   5 use warnings;
  1         2  
  1         66  
4              
5             package PGP::Words::Tiny;
6             # ABSTRACT: Convert data to/from the PGP word list
7             our $VERSION = '0.002'; # VERSION
8              
9 1     1   5 use Carp qw/croak/;
  1         2  
  1         76  
10 1     1   5 use Exporter 5.57 qw/import/;
  1         16  
  1         927  
11             our @EXPORT_OK = qw(encode_pgp decode_pgp encode_pgp_hex decode_pgp_hex);
12              
13             my ( @even, @odd, %rev_even, %rev_odd );
14              
15             sub encode_pgp {
16 3     3 1 7 my $c = 0;
17 3 100       10 return map { $c++ & 1 ? $odd[$_] : $even[$_] } unpack "C*", $_[0];
  42         169  
18             }
19              
20             sub decode_pgp {
21 3 100   3 1 20 my @input = @_ > 1 ? @_ : split " ", $_[0];
22 3         6 my ( $c, @data ) = 0;
23 3         5 for my $word (@input) {
24 42 100       96 my $value = ( $c++ & 1 ? $rev_odd{ lc $word } : $rev_even{ lc $word } );
25 42 50       72 croak "Encoding error detected at word $c ('$word')"
26             unless defined $value;
27 42         59 push @data, $value;
28             }
29 3         24 return pack "C*", @data;
30             }
31              
32             sub encode_pgp_hex {
33 2     2 1 24 my $string = shift;
34 2         10 $string =~ s/^0x//i;
35 2         12 return encode_pgp( pack "H*", $string );
36             }
37              
38             sub decode_pgp_hex {
39 2     2 1 8 return "0x" . unpack "H*", decode_pgp(@_);
40             }
41              
42             #<<< No perltidy
43              
44             @even = qw(
45             aardvark absurd accrue acme adrift adult afflict ahead aimless
46             Algol allow alone ammo ancient apple artist assume Athens atlas Aztec baboon
47             backfield backward banjo beaming bedlamp beehive beeswax befriend Belfast
48             berserk billiard bison blackjack blockade blowtorch bluebird bombast bookshelf
49             brackish breadline breakup brickyard briefcase Burbank button buzzard cement
50             chairlift chatter checkup chisel choking chopper Christmas clamshell classic
51             classroom cleanup clockwork cobra commence concert cowbell crackdown cranky
52             crowfoot crucial crumpled crusade cubic dashboard deadbolt deckhand dogsled
53             dragnet drainage dreadful drifter dropper drumbeat drunken Dupont dwelling
54             eating edict egghead eightball endorse endow enlist erase escape exceed
55             eyeglass eyetooth facial fallout flagpole flatfoot flytrap fracture framework
56             freedom frighten gazelle Geiger glitter glucose goggles goldfish gremlin
57             guidance hamlet highchair hockey indoors indulge inverse involve island jawbone
58             keyboard kickoff kiwi klaxon locale lockup merit minnow miser Mohawk mural
59             music necklace Neptune newborn nightbird Oakland obtuse offload optic orca
60             payday peachy pheasant physique playhouse Pluto preclude prefer preshrunk
61             printer prowler pupil puppy python quadrant quiver quota ragtime ratchet
62             rebirth reform regain reindeer rematch repay retouch revenge reward rhythm
63             ribcage ringbolt robust rocker ruffled sailboat sawdust scallion scenic
64             scorecard Scotland seabird select sentence shadow shamrock showgirl skullcap
65             skydive slingshot slowdown snapline snapshot snowcap snowslide solo southward
66             soybean spaniel spearhead spellbind spheroid spigot spindle spyglass stagehand
67             stagnate stairway standard stapler steamship sterling stockman stopwatch stormy
68             sugar surmount suspense sweatband swelter tactics talon tapeworm tempest tiger
69             tissue tonic topmost tracker transit trauma treadmill Trojan trouble tumor
70             tunnel tycoon uncut unearth unwind uproot upset upshot vapor village virus
71             Vulcan waffle wallet watchword wayside willow woodlark Zulu
72             );
73              
74             @odd = qw(
75             adroitness adviser aftermath aggregate alkali almighty amulet
76             amusement antenna applicant Apollo armistice article asteroid Atlantic
77             atmosphere autopsy Babylon backwater barbecue belowground bifocals bodyguard
78             bookseller borderline bottomless Bradbury bravado Brazilian breakaway
79             Burlington businessman butterfat Camelot candidate cannonball Capricorn caravan
80             caretaker celebrate cellulose certify chambermaid Cherokee Chicago clergyman
81             coherence combustion commando company component concurrent confidence
82             conformist congregate consensus consulting corporate corrosion councilman
83             crossover crucifix cumbersome customer Dakota decadence December decimal
84             designing detector detergent determine dictator dinosaur direction disable
85             disbelief disruptive distortion document embezzle enchanting enrollment
86             enterprise equation equipment escapade Eskimo everyday examine existence exodus
87             fascinate filament finicky forever fortitude frequency gadgetry Galveston
88             getaway glossary gossamer graduate gravity guitarist hamburger Hamilton
89             handiwork hazardous headwaters hemisphere hesitate hideaway holiness hurricane
90             hydraulic impartial impetus inception indigo inertia infancy inferno informant
91             insincere insurgent integrate intention inventive Istanbul Jamaica Jupiter
92             leprosy letterhead liberty maritime matchmaker maverick Medusa megaton
93             microscope microwave midsummer millionaire miracle misnomer molasses molecule
94             Montana monument mosquito narrative nebula newsletter Norwegian October Ohio
95             onlooker opulent Orlando outfielder Pacific pandemic Pandora paperweight
96             paragon paragraph paramount passenger pedigree Pegasus penetrate perceptive
97             performance pharmacy phonetic photograph pioneer pocketful politeness positive
98             potato processor provincial proximate puberty publisher pyramid quantity
99             racketeer rebellion recipe recover repellent replica reproduce resistor
100             responsive retraction retrieval retrospect revenue revival revolver sandalwood
101             sardonic Saturday savagery scavenger sensation sociable souvenir specialist
102             speculate stethoscope stupendous supportive surrender suspicious sympathy
103             tambourine telephone therapist tobacco tolerance tomorrow torpedo tradition
104             travesty trombonist truncated typewriter ultimate undaunted underfoot unicorn
105             unify universe unravel upcoming vacancy vagabond vertigo Virginia visitor
106             vocalist voyager warranty Waterloo whimsical Wichita Wilmington Wyoming
107             yesteryear Yucatan
108             );
109              
110             #>>> # no perl tidy
111              
112             @rev_even{ map { lc } @even } = 0 .. $#even;
113             @rev_odd{ map { lc } @odd } = 0 .. $#odd;
114              
115             1;
116              
117              
118             # vim: ts=2 sts=2 sw=2 et:
119              
120             __END__