From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6244 invoked from network); 14 Sep 2006 00:22:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.5 (2006-08-29) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 Sep 2006 00:22:37 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 69990 invoked from network); 14 Sep 2006 00:22:30 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 Sep 2006 00:22:30 -0000 Received: (qmail 22365 invoked by alias); 14 Sep 2006 00:22:22 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10712 Received: (qmail 22354 invoked from network); 14 Sep 2006 00:22:21 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 14 Sep 2006 00:22:21 -0000 Received: (qmail 68789 invoked from network); 14 Sep 2006 00:22:21 -0000 Received: from s1tank.virtdom.com (216.240.101.50) by a.mx.sunsite.dk with SMTP; 14 Sep 2006 00:22:19 -0000 Received: (qmail 16973 invoked by uid 89); 14 Sep 2006 01:17:48 -0000 Received: from static-72-76-44-42.nwrknj.fios.verizon.net (HELO venti) (brian@aljex.com@72.76.44.42) by s1tank.virtdom.com with SMTP; 14 Sep 2006 01:17:48 -0000 Message-ID: <03ba01c6d793$d3bd7110$6500000a@venti> From: "Brian K. White" To: References: <20060912150813.GA4937@ulpmm.u-strasbg.fr> <060912182718.ZM24284@torch.brasslantern.com> <20060913150818.GA9450@ulpmm.u-strasbg.fr> Subject: Re: base64 coding for zsh ? Date: Wed, 13 Sep 2006 20:21:47 -0400 Organization: Aljex Software MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 ----- Original Message ----- From: "Marc Chantreux" To: "zsh-users" Sent: Wednesday, September 13, 2006 11:08 AM Subject: Re: base64 coding for zsh ? le 12/09/2006, Bart Schaefer nous crivait : > It's about 50 lines of readably-formatted C code to write a base64 > decoder, so i'll write my first zsh module. It's added to my todo list. > slightly more than that to write the encoder, not counting the > lookup tables. It could be done in shell script, but it would be very > slow and probably not worth the effort. ok, i give this solution away. > alias enB64="perl -MMIME::Base64 -e 'print encode_base64(shift @ARGV)'" > alias deB64="perl -MMIME::Base64 -e 'print decode_base64(shift @ARGV)'" well ... i think perl is quite huge for this problem. I'll use openssl as temporary hack. alias B64enc='openssl base64' alias B64dec='openssl base64 -d' thanks for help. regards. ------------ I've been using the stand-alone: http://www.fourmilab.ch/webtools/base64/ I never realised I already had it in openssl. Thanks for the tip. This led me to see what else I might already have or could get in a ready made package rather than having to use a source. (I do need this util in some form on every box and previously all my boxes were SCO OpenServer and I had been using the fourmilab source for years.) Then I decided to run a few simple time tests, since this gets used a lot in various system() commands in application code and cgi scripts etc... I expected the simple plain base64 util to be the fastest but I was wrong: In each case I repeated the same command many times and always got almost exactly the same results, that is, +- 0m0.004 of the numbers shown so these are representative not just a fluke or caching effects or effects of the os being busy elsewhere. the fourmilab source: nj4:~ # time base64 /dev/null real 0m0.074s user 0m0.072s sys 0m0.000s openssl: nj4:~ # time opsnssl base64 /dev/null -bash: opsnssl: command not found real 0m0.001s user 0m0.000s sys 0m0.000s mimencode comes in the metamail package: nj4:~ # time mimencode /dev/null real 0m0.078s user 0m0.076s sys 0m0.004s gmime-uuencode: It actually does base64 not uuencode if you give it the -m or --base64 option. It comes in the gmime package. It prepends and appends some junk to the actual base64 output so it's inconvenient for me to actually use: nj4:~ # echo this is a test |gmime-uuencode -m - begin-base64 600 - dGhpcyBpcyBhIHRlc3QK ==== nj4:~ # As for the speed: nj4:~ # time gmime-uuencode -m - /dev/null real 0m0.009s user 0m0.008s sys 0m0.000s Ooenssl destroys the rest. So even though I have the dedicated util it's actually better to use openssl. As a side benefit, thats one less special thing to maintain on all my boxes. On a related note. I had/have a need for a standalone url encoder/decoder and made one myself, then receive the help of someone else to make it into a proper util with man page and getopts() and basic sanity checking etc... The source is here. I never bothered to make linux binaries except for myself yet but it's such basic code it builds with no problems anywhere. http://www.aljex.com/bkw/sco/#urldec Does anyone know of an already existing util to do that? I can't imagine how something so basic can be made 78 times faster but I would have said the same thing about base64 until now also. Note: I'd like it to work as a filter like cat, like all the utils above. In fact, my util has options to do both, work as a filter or take a string on the command line. Thanks. btw, compared to above, ick... nj4:~ # time urlenc /dev/null real 0m0.332s user 0m0.332s sys 0m0.000s Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/ +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!