package util; # # Description: Convert an ascii string to a hexidecimal string # and translate a hex string back to ascii. # #=============================================================== sub ascii_to_hex ($) { ## Convert each ASCII character to a two-digit hex number. (my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg; # $str = $str . "-"; return $str; } sub hex_to_ascii ($) { ## Convert each two-digit hex number back to an ASCII character. (my $str = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg; return $str; } 1;