(keitai-l) Re: Fun with Base64 Decoding

From: Ron Schei <ron_at_schei.com>
Date: 10/25/01
Message-Id: <4.3.2-J.20011025183234.00c12760@www.schei.com>
Hello,
Thanks for the responses!
Yes, I trimmed the padding (it took me Two lines- thanks for the tip!):

 >Anyway, all good perl should be done in one line... ;-)
 >print decode_base64($line =~ m/^\=\?ISO\-2022\-JP\?B\?(.*)\?=$/ && $1);

So just to make sure I'm not starting out with the wrong string,

=?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=
means that
GyRCRnxLXDhsGyhC
needs to be decoded, right?

Decoding the above string leaves me with an ISO-2022-JP string that I'd 
like to eventually send to an imode phone.
I've tried this ISO-2022-JP to EUC conversion (courtesy of the esteemed Mr. 
Lunde):

$line = decode_base64($line);
##### ISO-2022-JP to EUC ###
$line =~ s{
\e\$[\@B]
((?:[\x21-\x7E][\x21-\x7E])+)
\e\([BHJ]
}{($x = $1) =~ tr/\x21-\x7E/\xA1-\xFE/,
$x
}egx;
$line =~ s{
\e\(I
([\x21-\x7E]+)
\e\([BHJ]
}{($x = $1) =~ tr/\x21-\x7E/\xA1-\xFE/,
($y = $x) =~ s/([\xA1-\xFE])/\x8E$1/g,
$y
}egx;

but after all that work the poor line is still gibberish, or technically 
speaking:
J聶y匁焚臓悵・
The script itself is in EUC and I convert that to SJIS just before sending 
it back to the phone.
I tried converting it straight from ISO-2022-JP to Shift-JIS as well. It 
went something like this:
J跂yヒFノ臓ラハ
Any other ideas on how to get this line back into SJIS?
Thanks!
Ron


At 18:01 01/10/25 +0900, you wrote:
>Looks like he already did that:
>
> > ### ... detect a Base64 encoded line .. ###
> > ###   strip control characters, leaving this: GyRCRnxLXDhsGyhC ###
>
>So I'm guessing the issue is one of display. After base64 decoding, you will
>have a string of iso-2022-jp Japanese which will most likely NOT display
>correctly unless you've got a properly configured xterm or something. So it
>probably was working but unconfirmed as it displayed as gibberish.
>
>r e n


[ Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ ]
Received on Thu Oct 25 12:38:59 2001