Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Base64 Encode/Code

235 views
Skip to first unread message

mumpscode

unread,
Oct 23, 2010, 2:28:04 AM10/23/10
to
Someone has in your library a standard mumps routine that encode /
decode BASE64?

Thanks!

Alex

unread,
Oct 23, 2010, 5:03:04 AM10/23/10
to
OK I've been thinking about this as an Atmus library facility.

Base64 encoding is used to encode arbitrary binary content.

GT.M can operate in two modes M (ASCII) or UTF8.

I suppose what is being asked for is to encode and decode GT.M strings
in either mode.

There are two limitations that come to mind:
1) Encoding a string in one mode (UTF8) and decoding in a different
process running the other mode (ASCII) would not work. ie: bad
translation
2) Encoded strings will be about 33% larger than decoded strings. GT.M
has a string size limit of 1 megabyte. Trying to encode a string over
approximately 750KB will fail.

The facility should be able to detect which mode it is operating in so
you would have two simple extrinsic functions something like:

Set string64=$$zcoreString^Encode64(string)

Set string=$$zcoreString^Decode64(string)

Reading the Base64 entry on Wikipedia:
* There seems to be some variations on the default encoding characters
"+" and "/" depending on this whether one wants to use encoded strings
in URL parameters. ie: negate URL encoding the token. I suppose these
can be detected.
* Variable line length
* Whether to include end padding characters in encoding output

How would you intend to use a base64 encoded string in your program?
Do you wish to inter-operate encoded strings between an Mumps and a
non-Mumps program?
Any objections to a dependency on an existing "Base64" command line
utility to do the encoding and decoding or do you need a mumps
implementation of Base64 encoding? ie: no external dependencies.

Kind regards


Alex

Alex

unread,
Oct 23, 2010, 3:19:13 PM10/23/10
to
Hi mumpscode,

I've created a wrapper for the existing base64 utility on Linux.
You can see whether you have this utility installed try "base64" from
command line, and its usage via "man base64".

http://www.assembla.com/code/Atmus/subversion/nodes/trunk/core/zcoreEncoder.m?rev=46

It has a few limitations like not working with new line characters and
strings somewhere over 10,000 characters.
Maybe a proper mumps only tool can be written when we have more
detailed further requirements.

A good reference for wrapping utilities via pipe in mumps is explained
here:
http://www.fidelityinfoservices.com/user_documentation/html/rn_tb/PIPE_IO_Technical_Bulletin.html#id1027849

Cheers


Alex

Diogo Paiva

unread,
Oct 23, 2010, 4:15:41 PM10/23/10
to
On Oct 23, 5:19 pm, Alex <alexatwoodh...@gmail.com> wrote:
> Hi mumpscode,
>
> I've created a wrapper for the existing base64 utility on Linux.
> You can see whether you have this utility installed try "base64" from
> command line, and its usage via "man base64".
>
> http://www.assembla.com/code/Atmus/subversion/nodes/trunk/core/zcoreE...

>
> It has a few limitations like not working with new line characters and
> strings somewhere over 10,000 characters.
> Maybe a proper mumps only tool can be written when we have more
> detailed further requirements.
>
> A good reference for wrapping utilities via pipe in mumps is explained
> here:http://www.fidelityinfoservices.com/user_documentation/html/rn_tb/PIP...

Hi Alex

Thanks for your lot of explanation.

Good guy! Nice to meet you!

I need this routine just for encode and decode usernames and
passwords to login on a ESMTP server directly from my mumps
implementation and send small mail messages.

If you've got a standard mumps routine with these two functions
and could publish it here I think that you'll help many
programmers.

But I'm not using GTM and Linux and I can't use OS recurses
on my mumps implementation (I'm still using DTM over a PCTCP
Kernel under MS-DOS) then I think that I'll need learn about
theses algorithms and write my own routine to do this.

Thanks again.

Cheers!

ps: Sorry for my poor english.

glilly

unread,
Oct 24, 2010, 3:16:01 AM10/24/10
to
On Oct 23, 2:28 am, mumpscode <mumpsc...@hotmail.com> wrote:

There are a couple of standard routines in VistA, which are public
domain:
gpl

ENCODE(X) ;
N RGZ,RGZ1,RGZ2,RGZ3,RGZ4,RGZ5,RGZ6
S RGZ=$$INIT,RGZ1=""
F RGZ2=1:3:$L(X) D
.S RGZ3=0,RGZ6=""
.F RGZ4=0:1:2 D
..S RGZ5=$A(X,RGZ2+RGZ4),RGZ3=RGZ3*256+$S(RGZ5<0:0,1:RGZ5)
.F RGZ4=1:1:4 S RGZ6=$E(RGZ,RGZ3#64+2)_RGZ6,RGZ3=RGZ3\64
.S RGZ1=RGZ1_RGZ6
S RGZ2=$L(X)#3
S:RGZ2 RGZ3=$L(RGZ1),$E(RGZ1,RGZ3-2+RGZ2,RGZ3)=$E("==",RGZ2,2)
Q RGZ1
DECODE(X) ;
N RGZ,RGZ1,RGZ2,RGZ3,RGZ4,RGZ5,RGZ6
S RGZ=$$INIT,RGZ1=""
F RGZ2=1:4:$L(X) D
.S RGZ3=0,RGZ6=""
.F RGZ4=0:1:3 D

.S RGZ3=0,RGZ6=""
.F RGZ4=0:1:3 D
..S RGZ5=$F(RGZ,$E(X,RGZ2+RGZ4))-3
..S RGZ3=RGZ3*64+$S(RGZ5<0:0,1:RGZ5)
.F RGZ4=0:1:2 S RGZ6=$C(RGZ3#256)_RGZ6,RGZ3=RGZ3\256
.S RGZ1=RGZ1_RGZ6
Q $E(RGZ1,1,$L(RGZ1)-$L(X,"=")+1)
INIT() Q
"=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

mumpscode

unread,
Oct 28, 2010, 1:19:43 AM10/28/10
to

Thanks Alex and Glilly!

I think that solved my problem.

Cheers!

mumpscode

unread,
Oct 28, 2010, 1:21:07 AM10/28/10
to
On Oct 24, 5:16 am, glilly <tangogeo...@gmail.com> wrote:

Thanks Alex and Glilly!

Allan

unread,
Aug 30, 2017, 10:10:13 PM8/30/17
to
Just wanted to make a shout out to GILLY. Your code snipet to encode/decode base64 has saved me hours and hours.

Thanks 7 years later!

jonasg...@gmail.com

unread,
Feb 27, 2018, 1:38:47 PM2/27/18
to
Diogo Paiva,

Can you share the utilities and how did you make PCTCP to work?

And if you have any way to acesso DTM database from other languages,

And also if you can acess other databases from DTM.

Yours,

0 new messages