File: 00_enc_dec.t

package info (click to toggle)
libconvert-base32-perl 0.06-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 76 kB
  • sloc: perl: 83; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;

use Test::More;

use Convert::Base32 qw( encode_base32 decode_base32 );

my @tests = (
    [ "\x3a\x27\x0f\x93"     => 'hitq7ey'  ],
    [ "\x3a\x27\x0f\x93\x2a" => 'hitq7ezk' ],
);

{
    my @syms = ( 'a'..'z', '2'..'7' );
    my $e;
    my $d;
    for (0..$#syms) {
	my $sym = $syms[$_];
	$e .= "aaaaaaa$sym";
	$d .= pack('C5', 0,0,0,0,$_);
    }
    push @tests, [ $d, $e ];
}

{
    my $d = join '', map chr, 0..255;
    my $e = join '', qw(
	aaaqeayeaudaocajbifqydiob4ibceqtcqkrmfyy
	denbwha5dypsaijcemsckjrhfausukzmfuxc6mbr
	giztinjwg44dsor3hq6t4p2aifbegrcfizduqskk
	jnge2tspkbiveu2ukvlfowczljnvyxk6l5qgcytd
	mrswmz3infvgw3dnnzxxa4lson2hk5txpb4xu634
	pv7h7aebqkbyjbmgq6eitculrsgy5d4qsgjjhfev
	s2lzrgm2tooj3hu7ucq2fi5euwtkpkfjvkv2zlno
	v6yldmvtws23nn5yxg5lxpf5x274bqocypcmlrwh
	zde4vs6mzxhm7ugr2lj5jvow27mntww33to55x7a
	4hrohzhf43t6r2pk5pwo33xp6dy7f47u6x3pp6hz
	7l57z7p674
    );
    push @tests, [ $d, $e ];
}

plan tests => 3 * @tests;

sub hexify {
    my $s = $_[0];
    $s =~ s/(.)/ sprintf '%02X ', ord($1) /seg;
    chop $s;
    return $s;
}

for (@tests) {
    my $d = $_->[0];
    my $e = lc($_->[1]);
    my $E = uc($_->[1]);

    is        encode_base32($d),         $e,  "encode ".hexify($d);
    is hexify(decode_base32($e)), hexify($d), "decode $e";
    is hexify(decode_base32($E)), hexify($d), "decode $E";
}