| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package String::HexConvert; ## Converts ascii strings to hex and reverse |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION='0.01'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
51972
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
57
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
99
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
221
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [qw( |
|
15
|
|
|
|
|
|
|
hex_to_ascii |
|
16
|
|
|
|
|
|
|
ascii_to_hex |
|
17
|
|
|
|
|
|
|
)] ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Exporter::export_ok_tags('all'); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# It is a wrapper around pack and unpack of perl to convert a string of hex digits |
|
23
|
|
|
|
|
|
|
# to ascii and other way around. |
|
24
|
|
|
|
|
|
|
# |
|
25
|
|
|
|
|
|
|
# SYNOPSIS |
|
26
|
|
|
|
|
|
|
# ======== |
|
27
|
|
|
|
|
|
|
# |
|
28
|
|
|
|
|
|
|
# use String::HexConvert ':all'; |
|
29
|
|
|
|
|
|
|
# |
|
30
|
|
|
|
|
|
|
# print ascii_to_hex("hello world"); # writes: 68656c6c6f20776f726c64 |
|
31
|
|
|
|
|
|
|
# |
|
32
|
|
|
|
|
|
|
# print hex_to_ascii("68656c6c6f20776f726c64"); # writes: hello world |
|
33
|
|
|
|
|
|
|
# |
|
34
|
|
|
|
|
|
|
# |
|
35
|
|
|
|
|
|
|
# |
|
36
|
|
|
|
|
|
|
# SEE ALSO |
|
37
|
|
|
|
|
|
|
# ======== |
|
38
|
|
|
|
|
|
|
# pack, unpack, L |
|
39
|
|
|
|
|
|
|
# |
|
40
|
|
|
|
|
|
|
# LICENSE |
|
41
|
|
|
|
|
|
|
# ======= |
|
42
|
|
|
|
|
|
|
# You can redistribute it and/or modify it under the conditions of LGPL. |
|
43
|
|
|
|
|
|
|
# |
|
44
|
|
|
|
|
|
|
# WHY? |
|
45
|
|
|
|
|
|
|
# ==== |
|
46
|
|
|
|
|
|
|
# In know the comments like "is that realy needed?". IMHO yes, because I forget the |
|
47
|
|
|
|
|
|
|
# exact syntax and possibilities of pack and unpack but hex_to_ascii tells me directly |
|
48
|
|
|
|
|
|
|
# what pack "H*" does. |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
# AUTHOR |
|
51
|
|
|
|
|
|
|
# ====== |
|
52
|
|
|
|
|
|
|
# Andreas Hernitscheck ahernit(AT)cpan.org |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Converts pairs of hex digits to asci |
|
56
|
|
|
|
|
|
|
sub hex_to_ascii { # $ascii ($hex) |
|
57
|
1
|
|
|
1
|
1
|
3
|
my $s = shift; |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
11
|
return pack 'H*', $s; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Converts a string to pairs of hex digits |
|
63
|
|
|
|
|
|
|
sub ascii_to_hex { # $hex ($ascii) |
|
64
|
1
|
|
|
1
|
1
|
8
|
my $s = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
13
|
return unpack("H*", $s); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
|
70
|
|
|
|
|
|
|
#################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
String::HexConvert - Converts ascii strings to hex and reverse |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use String::HexConvert ':all'; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
print ascii_to_hex("hello world"); # writes: 68656c6c6f20776f726c64 |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
print hex_to_ascii("68656c6c6f20776f726c64"); # writes: hello world |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
It is a wrapper around pack and unpack of perl to convert a string of hex digits |
|
93
|
|
|
|
|
|
|
to ascii and other way around. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 REQUIRES |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 ascii_to_hex |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $hex = ascii_to_hex($ascii); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Converts a string to pairs of hex digits |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 hex_to_ascii |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $ascii = hex_to_ascii($hex); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Converts pairs of hex digits to asci |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 WHY? |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
In know the comments like "is that realy needed?". IMHO yes, because I forget the |
|
122
|
|
|
|
|
|
|
exact syntax and possibilities of pack and unpack but hex_to_ascii tells me directly |
|
123
|
|
|
|
|
|
|
what pack "H*" does. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
pack, unpack, L |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Andreas Hernitscheck ahernit(AT)cpan.org |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 LICENSE |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can redistribute it and/or modify it under the conditions of LGPL. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|