我想编写一个非常简单的脚本来“编码”和“解码”字符串,方法是将每个字符替换为一个数字,并启用延迟扩展。但是我使用的语法应该是错误的,因为它根本不起作用。
此外,是否有一种方法可以执行区分大小写的替换,以恢复原始字符串?
@echo off
setlocal EnableDelayedExpansion
set "alphabet=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "offset=15"
set "delimiter=-"
set "string=TeSt 123 tEsT 456"
set encoded=!string!
for /l %%N in (0 1 61) do (
set "char=!alphabet:~%%N,1!"
set /a "code=%%N+!offset!"
echo !char! = !code!
set "encoded=!encoded:%char%=%code%%delimiter%!"
)
set decoded=!encoded!
for /l %%N in (0 1 61) do (
set "char=!alphabet:~%%N,1!"
set /a "code=%%N+!offset!"
echo !code! = !char!
set "decoded=!decoded:%code%%delimiter%=%char%!"
)
echo original: !string!
echo encoded: !encoded!
echo decoded: !decoded!
pause
exit
谢谢!