Tcl Expect:变量发送响应复杂的身份验证提示

时间:2016-12-27 01:03:41

标签: regex login tcl expect telnet

这是已知使用Telnet服务器的TCL脚本的相关部分的摘录。

#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}
package require Expect
#USER
set user xyz
set secret 12345678
set smr AB1CDE-11
set host foo.bar
#TELNET START
spawn telnet $host
expect "\[Login :\]"
send "$user\r";
expect "=>"
#RMS
send "c $smr gate\r";
expect "$smr >"
send "PW $secret\r"
expect "\[>\]"

几天前登录程序已更改。无法再使用send "PW $secret\r"回复。在$smr >响应之后,可以发送任何命令以启动登录,例如send "login\r"。 telnet以Login [517]:响应。 []内的数字对应$secret中的位置。完整的$secrect响应不再成功。服务器需要一个响应,其中包含所有三个字符以及另外三个字符。

由于某些原因,我希望$secret中的字符位置在三个随机字符中的随机位置(RegEx术语中可能的字符:[A-Z0-9.!@#$%^&*()_])。 $secret的长度是可变的。所以我无法为每个角色设置一个变量来回应它们与RegEx matchresult。

用于捕获字符位置的正确RegExp将是LOGIN \[(\d)(\d)(\d)]:,对吗?我已经达到以下目的(输出被捕获在文本文件中以进行统计后处理,因为我正在评估登录过程的随机性)。

send "login\r"    
set input [open output_$user.txt a]
set output $expect_out(buffer)
puts $input $output
close $input
expect "LOGIN"
#Check LOGIN prompt
set file [read [open "output_$user.txt" r]]
if [
regexp -nocase {LOGIN \[(\d)(\d)(\d)]:} 
] then {
send "RESPONSE\r";
}

如何使用TCL解决此问题?谢谢!

修订:
使用send "c $smr gate\r";

连接到Telnet服务器后
XYZ SMC via AB1CDE-11 >
正在回复

,这是expect "$smr >"所期待的。直到这里,一切正常 对于以下send "login\r",Telnet服务器回复两行:

Login [517]:
XYZ SMC via AB1CDE-11 >

匹配的RegEx为Login \[(\d)(\d)(\d)\]:\n.*>。 我尝试过不同的期望RegEx语法:
Donal-fellows expect -re {Login \[(\d)(\d)(\d)\]:} TCL的崩溃 expect -re -n {Login \[(\d)(\d)(\d)\]:\n.*>} TCL的崩溃 expect {-re -n "Login \[(\d)(\d)(\d)\]:"}退出
只有没有正则表达式(-re)的内容(如expect "$smr >"expect "LOGIN")才能正常工作,而TCL不会退出。
TCL appcompat(FOLDER的PATH已被匿名化):

<?xml version="1.0" encoding="UTF-16"?>
<DATABASE>
<EXE NAME="tclsh.exe" FILTER="GRABMI_FILTER_PRIVACY">
    <MATCHING_FILE NAME="base-tcl8.6-thread-win32-ix86.dll" SIZE="2023820" CHECKSUM="0xFCEB4A60" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tcl DLL" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tcl86.dll" LEGAL_COPYRIGHT="Copyright © 2001 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x1693A0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:56:02" UPTO_LINK_DATE="03/12/2015 23:56:02" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="base-tcl8.6-thread-win32-ix86.exe" SIZE="2445716" CHECKSUM="0x2B1899DD" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tclsh Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tclsh86s.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:41:45" UPTO_LINK_DATE="03/12/2015 23:41:45" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="base-tk8.6-thread-win32-ix86.exe" SIZE="3713462" CHECKSUM="0xB94B598D" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="ActiveState Basekit" COMPANY_NAME="ActiveState Software Inc." PRODUCT_NAME="TDK Basekit 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="basekit.exe" LEGAL_COPYRIGHT="Copyright © 2009 by ActiveState Software Inc." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:46:01" UPTO_LINK_DATE="03/12/2015 23:46:01" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="tcl86.dll" SIZE="1228800" CHECKSUM="0x3BC33EBF" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tcl DLL" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tcl86.dll" LEGAL_COPYRIGHT="Copyright © 2001 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x12F33A" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 22:59:49" UPTO_LINK_DATE="03/12/2015 22:59:49" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="tclsh.exe" SIZE="393216" CHECKSUM="0x9050007E" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tclsh Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tclsh86.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 22:59:57" UPTO_LINK_DATE="03/12/2015 22:59:57" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="tclsh86.exe" SIZE="393216" CHECKSUM="0x9050007E" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tclsh Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tclsh86.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 22:59:57" UPTO_LINK_DATE="03/12/2015 22:59:57" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="teacup.exe" SIZE="3259545" CHECKSUM="0xFDE41297" BIN_FILE_VERSION="8.5.2.18" BIN_PRODUCT_VERSION="8.5.2.18" PRODUCT_VERSION="8.5.18" FILE_DESCRIPTION="Tclsh Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.5 for Windows" FILE_VERSION="8.5.18" ORIGINAL_FILENAME="tclsh85s.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.5.2.18" UPTO_BIN_PRODUCT_VERSION="8.5.2.18" LINK_DATE="03/12/2015 04:34:28" UPTO_LINK_DATE="03/12/2015 04:34:28" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="tk86.dll" SIZE="1433600" CHECKSUM="0x9963D526" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tk DLL" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tk 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tk86.dll" LEGAL_COPYRIGHT="Copyright © 2001 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x162A03" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:31:57" UPTO_LINK_DATE="03/12/2015 23:31:57" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="wish.exe" SIZE="393216" CHECKSUM="0x4A8216DD" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Wish Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tk 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="wish86.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:31:58" UPTO_LINK_DATE="03/12/2015 23:31:58" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="wish86.exe" SIZE="393216" CHECKSUM="0x4A8216DD" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Wish Application" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tk 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="wish86.exe" LEGAL_COPYRIGHT="Copyright © 2000 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x1" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 23:31:58" UPTO_LINK_DATE="03/12/2015 23:31:58" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="zlib1.dll" SIZE="107520" CHECKSUM="0x6E91C07D" BIN_FILE_VERSION="1.2.8.0" BIN_PRODUCT_VERSION="1.2.8.0" PRODUCT_VERSION="1.2.8" FILE_DESCRIPTION="zlib data compression library" PRODUCT_NAME="zlib" FILE_VERSION="1.2.8" ORIGINAL_FILENAME="zlib1.dll" INTERNAL_NAME="zlib1.dll" LEGAL_COPYRIGHT="(C) 1995-2013 Jean-loup Gailly &amp; Mark Adler" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x20A00" LINKER_VERSION="0x10000" UPTO_BIN_FILE_VERSION="1.2.8.0" UPTO_BIN_PRODUCT_VERSION="1.2.8.0" LINK_DATE="05/13/2013 12:42:08" UPTO_LINK_DATE="05/13/2013 12:42:08" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="FOLDER\freewrap.exe" SIZE="8674276" CHECKSUM="0x87EABBB8" MODULE_TYPE="WIN32" PE_CHECKSUM="0x347472" LINKER_VERSION="0x10000" LINK_DATE="02/22/1970 08:06:24" UPTO_LINK_DATE="02/22/1970 08:06:24" />
    <MATCHING_FILE NAME="FOLDER\freewrap664\win32\freewrap.exe" SIZE="8674276" CHECKSUM="0x87EABBB8" MODULE_TYPE="WIN32" PE_CHECKSUM="0x347472" LINKER_VERSION="0x10000" LINK_DATE="02/22/1970 08:06:24" UPTO_LINK_DATE="02/22/1970 08:06:24" />
    <MATCHING_FILE NAME="FOLDER\freewrap664\win32\freewrapTCLSH.exe" SIZE="5935627" CHECKSUM="0x4728114A" MODULE_TYPE="WIN32" PE_CHECKSUM="0x1E8C2F" LINKER_VERSION="0x10000" LINK_DATE="07/04/1971 17:12:48" UPTO_LINK_DATE="07/04/1971 17:12:48" />
    <MATCHING_FILE NAME="FOLDER\freewrap664\win64\freewrap.exe" SIZE="9044047" CHECKSUM="0xEAAC5906" MODULE_TYPE="WIN32" PE_CHECKSUM="0x3406BC" LINKER_VERSION="0x0" LINK_DATE="01/19/2015 01:41:48" UPTO_LINK_DATE="01/19/2015 01:41:48" />
    <MATCHING_FILE NAME="FOLDER\freewrap664\win64\freewrapTCLSH.exe" SIZE="6025630" CHECKSUM="0xD1018E6A" MODULE_TYPE="WIN32" PE_CHECKSUM="0x1D252E" LINKER_VERSION="0x0" LINK_DATE="01/15/2015 01:21:20" UPTO_LINK_DATE="01/15/2015 01:21:20" />
    <MATCHING_FILE NAME="FOLDER\kit\tclkit.exe" SIZE="1334267" CHECKSUM="0xEFE507F5" BIN_FILE_VERSION="8.5.2.9" BIN_PRODUCT_VERSION="8.5.2.9" PRODUCT_VERSION="8.5.9" FILE_DESCRIPTION="Tclkit, a standalone runtime for Tcl/Tk" COMPANY_NAME="Equi4 Software" PRODUCT_NAME="Tclkit 8.5 for Windows" FILE_VERSION="8.5.9" ORIGINAL_FILENAME="tclkit-gui.exe" LEGAL_COPYRIGHT="Copyright © 1989-2009 by J.Ousterhout et al." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.5.2.9" UPTO_BIN_PRODUCT_VERSION="8.5.2.9" LINK_DATE="09/09/2010 09:22:14" UPTO_LINK_DATE="09/09/2010 09:22:14" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="FOLDER\kit\tclkit2.exe" SIZE="1334267" CHECKSUM="0xEFE507F5" BIN_FILE_VERSION="8.5.2.9" BIN_PRODUCT_VERSION="8.5.2.9" PRODUCT_VERSION="8.5.9" FILE_DESCRIPTION="Tclkit, a standalone runtime for Tcl/Tk" COMPANY_NAME="Equi4 Software" PRODUCT_NAME="Tclkit 8.5 for Windows" FILE_VERSION="8.5.9" ORIGINAL_FILENAME="tclkit-gui.exe" LEGAL_COPYRIGHT="Copyright © 1989-2009 by J.Ousterhout et al." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.5.2.9" UPTO_BIN_PRODUCT_VERSION="8.5.2.9" LINK_DATE="09/09/2010 09:22:14" UPTO_LINK_DATE="09/09/2010 09:22:14" VER_LANGUAGE="Englisch (USA) [0x409]" />
    <MATCHING_FILE NAME="FOLDER\kit\tclkit864.exe" SIZE="3933431" CHECKSUM="0x717476F1" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tclkit, a standalone runtime for Tcl/Tk" COMPANY_NAME="Equi4 Software" PRODUCT_NAME="Tclkit 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tclkit-gui.exe" LEGAL_COPYRIGHT="Copyright © 1989-2009 by J.Ousterhout et al." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="04/12/2015 23:13:37" UPTO_LINK_DATE="04/12/2015 23:13:37" VER_LANGUAGE="Englisch (USA) [0x409]" />
</EXE>
<EXE NAME="tcl86.dll" FILTER="GRABMI_FILTER_THISFILEONLY">
    <MATCHING_FILE NAME="tcl86.dll" SIZE="1228800" CHECKSUM="0x3BC33EBF" BIN_FILE_VERSION="8.6.2.4" BIN_PRODUCT_VERSION="8.6.2.4" PRODUCT_VERSION="8.6.4" FILE_DESCRIPTION="Tcl DLL" COMPANY_NAME="ActiveState Corporation" PRODUCT_NAME="Tcl 8.6 for Windows" FILE_VERSION="8.6.4" ORIGINAL_FILENAME="tcl86.dll" LEGAL_COPYRIGHT="Copyright © 2001 by ActiveState Corporation, et al" VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x4" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x12F33A" LINKER_VERSION="0x0" UPTO_BIN_FILE_VERSION="8.6.2.4" UPTO_BIN_PRODUCT_VERSION="8.6.2.4" LINK_DATE="03/12/2015 22:59:49" UPTO_LINK_DATE="03/12/2015 22:59:49" VER_LANGUAGE="Englisch (USA) [0x409]" />
</EXE>
<EXE NAME="kernel32.dll" FILTER="GRABMI_FILTER_THISFILEONLY">
    <MATCHING_FILE NAME="kernel32.dll" SIZE="1067008" CHECKSUM="0xD3859AE" BIN_FILE_VERSION="5.1.2600.6532" BIN_PRODUCT_VERSION="5.1.2600.6532" PRODUCT_VERSION="5.1.2600.6532" FILE_DESCRIPTION="Client-DLL für Windows NT-Basis-API" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="Betriebssystem Microsoft® Windows®" FILE_VERSION="5.1.2600.6532 (xpsp_sp3_qfe.140312-0419)" ORIGINAL_FILENAME="kernel32" INTERNAL_NAME="kernel32" LEGAL_COPYRIGHT="© Microsoft Corporation. Alle Rechte vorbehalten." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x40004" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0x10EBEB" LINKER_VERSION="0x50001" UPTO_BIN_FILE_VERSION="5.1.2600.6532" UPTO_BIN_PRODUCT_VERSION="5.1.2600.6532" LINK_DATE="03/12/2014 10:48:40" UPTO_LINK_DATE="03/12/2014 10:48:40" VER_LANGUAGE="Deutsch (Deutschland) [0x407]" />
</EXE>
</DATABASE>

是的,我正在使用Windows。由于this issue,无法使用Linux执行此任务 我该怎么办?

1 个答案:

答案 0 :(得分:1)

嗯,通过使用Expect的更多功能,您可以相当轻松地完成一些操作。特别是,expect命令可以等待正则表达式匹配并报告匹配的子字符串,然后使用string index从秘密中挑选字符。

expect -re {Login \[(\d)(\d)(\d)\]:}
# It's wise to copy these values from expect_out into other variables immediately
set digitA $expect_out(1,string)
set digitB $expect_out(2,string)
set digitC $expect_out(3,string)

# Is it zero-based or one-based indexing? Assuming the latter...
set charA [string index $secret [expr {$digitA - 1}]]
set charB [string index $secret [expr {$digitB - 1}]]
set charC [string index $secret [expr {$digitC - 1}]]

我不太确定你是如何将这些信件收集到回复中的 - 你的描述不够清楚 - 但我相信你现在可以弄明白你已经得到了原料。