Thanks!
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
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
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.
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+/"
Thanks Alex and Glilly!
I think that solved my problem.
Cheers!