(keitai-l) Re: Fun with Base64 Decoding

From: Joran Roslund <joran_roslund_at_hotmail.com>
Date: 10/26/01
Message-ID: <F208dlQgdYXSVvR0Wss00019796@hotmail.com>
Hi,

I don't have Japanese language support on the machine I'm using
right now, but I decode your message to "Nihongo". The decoding
is simple, albeit a bit time-consuming to do by hand.

GyRCRnxLXDhsGyhC decodes as
Base-64:          G      y      R     C       R     n       x     L      X   
...
Decoded (dec):    6     50     17     2      17     39     49    11     23
Decoded (bin): 000110 110010 010001 010001 100111 100111 110001 001011 
010111
Regroup(8):    00011011 00100100 01010001 10011110 01111100 01001011
Hex:             1D         24      42      46        7C       4B
ASCII:           ESC         $       B       F         |        K

(Base-64 decoding table is found in e.g. 
http://www.faqs.org/rfcs/rfc2045.html)

Now, <ESC>$B means "start Japanese"
0x467C is JIS for "sun", NICHI
0x4B5C is JIS for "book", HON
0x386C is JIS for "language", GO
<ESC>(J means "end Japanese"

(For more info on ISO-2022-JP, 
ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/cjk.inf)

JIS is finally converted to S-JIS with the following code.
Let $msb be the Most Significant Byte of the JIS code
and $lsb    the Least Significant one.

$serial = $msb*94 + $lsb - 3135;
$sjis_msb = int($serial/188) + ( (int($serial/188) > 30) ? 193 : 129);
$sjis_lsb = $serial%188 + ( (($serial%188) > 62) ? 65 : 64);

(PERL gurus can probably do this in one line.)

$sjis_msb is now the Most Significant Byte of the Shift-JIS code.
$sjis_lsb is     the Least Significant one.

This alogoritm returns for the three kanjis above:

0x93FA
0x967B
0x386C

which are the correct values.

BR

Joran

DISCLAIMER: The JIS->S-JIS conversion is just something I wrote up
right now. I think it should be valid for all Japanese characters, but
please do your own verification.


>From: Jöran Roslund (EMW)  <Joran.Roslund@emw.ericsson.se>
>To: "'joran_roslund@hotmail.com'" <joran_roslund@hotmail.com>
>Subject: FW: (keitai-l) Re: Fun with Base64 Decoding
>Date: Fri, 26 Oct 2001 07:27:42 +0200
>
>
>
>-----Original Message-----
>From: Ron Schei [mailto:ron.schei@tsutaya.co.jp]
>Sent: den 26 oktober 2001 04.37
>To: keitai-l@appelsiini.net
>Subject: (keitai-l) Re: Fun with Base64 Decoding
>
>
>Hello,
>
> > OK let's take a step back. If you're trying to send email to imode,
>
>Sorry, I should have been clearer about what the script is for. I'm not
>sending mail to an imode, I'm checking my pop accounts using the imode
>browser. It checks my pop accounts, returns the From and Subject info,
>and allows me to view or delete messages. Right now the only snag is
>dealing wih Japanese subject lines. I can't get the Base64 ISO-2022-JP
>string into S-JIS. This leaves me with:
>
>From: meiwakumeru@milky-house.com
>Subject: =?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=
>[View][Delete]
>
>I've never had to deal with converting iso-2022-jp to sjis before. Any
>veterans out there willing to share their experiences?
>Thanks,
>Ron Schei
>
>
>
>
>[ Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ ]


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


[ Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ ]
Received on Fri Oct 26 08:33:23 2001