PetaMem has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to encode an arbitrary string (may be a perl source in UTF-8 encoding) to a well defined set of characters.
So - something similar to uuencode (pack "u"), but with a defined character set (e.g. only [A-Za-z0-9]) for the encoding string.
Of course, back and forth encoding/decoding should be possible to prevent creation of a write-only device. ;-)
Basically I have only a reduced character set in my "storage" available - about 6bit per character (64 characters) Currently, my best stab at it would be to uuencode the arbitrary string, and do some tr/// on the uuencoded string. Any better ideas?
Update:
I've actually implemented this now for encoding:and decoding:my $uuenc = pack "u", $string; $uuenc =~ tr/:;"$%&\/()'*#[]<>@`=,.+-/abcdefghijklmnopqrstuvw/;
Works for me. My primary objective was to *avoid* specific characters that are used otherwise ( ) < > | , etc.my $uudec = $uuenc; $uudec =~ tr/abcdefghijklmnopqrstuvw/:;"$%&\/()'*#[]<>@`=,.+-/; $uudec = unpack "u", $uudec;
Bye
PetaMem All Perl: MT, NLP, NLU
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Map octets to set of characters
by nobull (Friar) on Jan 30, 2005 at 18:20 UTC | |
|
Re: Map octets to set of characters
by ambrus (Abbot) on Jan 30, 2005 at 19:47 UTC |