I'm trying to write a customization in Lyris ListManager (10.2). The language is TCL, which I know very little about. We need to encode a value as base64 (or really, anything that obfuscates a querystring parameter), but I can't seem to figure out how. Is there a command native to TCL to do this?
+2
A:
The existence of http://tcllib.sourceforge.net/doc/base64.html seems to indicate that there're no native functions. You could copy the source and add it to your modifications.
% base64::encode "Hello, world"
SGVsbG8sIHdvcmxk
% base64::encode [string repeat xyz 20]
eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
eHl6eHl6eHl6
% base64::encode -wrapchar "" [string repeat xyz 20]
eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6eHl6
# NOTE: base64 encodes BINARY strings.
% set chemical [encoding convertto utf-8 "C\u2088H\u2081\u2080N\u2084O\u2082"]
% set encoded [base64::encode $chemical]
Q+KCiEjigoHigoBO4oKET+KCgg==
% set caffeine [encoding convertfrom utf-8 [base64::decode $encoded]]
Vinko Vrsalovic
2009-12-02 15:59:29
So if I copy the base64.tcl file into that folder, is there a way to import it so I can make the call?
Chad
2009-12-02 18:01:19
You can run the command "source base64.tcl" to load the file into the current namespace.
Bryan Oakley
2009-12-02 18:54:44
when I try to use source base64.tcl I get the following *invalid command name "source" while executing "source "base64.tcl""*
Chad
2009-12-02 19:51:11
If it doesn't recognise the source command - http://docs.activestate.com/activetcl/8.5/tcl/TclCmd/source.htm - then it's not standard Tcl. You will have to consult Lyris's documentation to find how they have modified it.
Colin Macleod
2009-12-03 08:24:12
+1
A:
If it would be good enough to just encode in hexadecimal, you can use the binary command as follows:
% set query "Hello, world"
Hello, world
% binary scan $query H* hexquery
1
% puts $hexquery
48656c6c6f2c20776f726c64
Colin Macleod
2009-12-03 08:54:28
+2
A:
Following your problem to use the base64 package you can use these little procs to convert your data to hex and back. Requires Tcl > 8
proc BIN2HEX { text } { binary scan $text H* result; return $result }
proc HEX2BIN { hex } { return [binary format H* $hex] }
set hex [BIN2HEX $yourText]
set textAgain [HEX2BIN $hex]
If you really need base64 you can just copy/paste the entire base64 file from the tcllib distribution http://sourceforge.net/projects/tcllib/files/tcllib/1.11.1/ into your code (remove the "package provides" line)
Nir Levy
2009-12-03 10:32:51
While the other answers are all good, this worked perfectly. I just had to copy/paste those methods, call them and I was done. Thanks... I wish Lyris support was as good as Stack Overflow
Chad
2009-12-03 15:37:58