将值编码为 base64

发布于 2024-08-13 01:36:21 字数 132 浏览 5 评论 0原文

我正在尝试在 Lyris ListManager (10.2) 中编写自定义。语言是TCL,我对此知之甚少。我们需要将一个值编码为base64(或者实际上是任何混淆查询字符串参数的值),但我似乎不知道如何编码。 TCL 是否有本地命令可以执行此操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往日情怀 2024-08-20 01:36:21

根据使用 base64 包的问题,​​您可以使用这些小过程将数据转换为十六进制并返回。需要 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]

如果您确实需要base64,您可以从tcllib发行版复制/粘贴整个base64文件 http://sourceforge.net/projects/tcllib/files/tcllib/1.11.1/ 进入您的代码(删除“packageprovided”行)

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)

静待花开 2024-08-20 01:36:21

http://tcllib.sourceforge.net/doc/base64.html 的存在似乎表明没有本机函数。您可以复制源并将其添加到您的修改中。

% 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]]

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]]
時窥 2024-08-20 01:36:21

如果您能够将 Tcl 库(包/模块)加载到您的环境中,则只需使用 Tcllib 实现。这就是 Vinko Vrsalovic 在他的回应中所显示的命令。

% package require base64
2.4
% base64::encode bob
Ym9i

If you have the ability to load Tcl libraries (packages/modules) into your environment, you can just use the Tcllib implementation. That's what Vinko Vrsalovic was showing the command from in his response.

% package require base64
2.4
% base64::encode bob
Ym9i
绅士风度i 2024-08-20 01:36:21

如果仅以十六进制编码就足够了,您可以使用 二进制命令如下:

% set query "Hello, world"
Hello, world
% binary scan $query H* hexquery
1
% puts $hexquery
48656c6c6f2c20776f726c64

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文