1 Need help to shorten the code
2.(If posible) about case sensitive when mapping
Sample.Bat:
@echo off & setlocal EnableDelayedExpansion
set "Data=HELLO"
:Encrypt/Decrypt_Rot13
set Encrypted_Data=!Data!
set Encrypted_Data=!Encrypted_Data:A=A#!
set Encrypted_Data=!Encrypted_Data:B=B#!
set Encrypted_Data=!Encrypted_Data:C=C#!
set Encrypted_Data=!Encrypted_Data:D=D#!
set Encrypted_Data=!Encrypted_Data:E=E#!
set Encrypted_Data=!Encrypted_Data:F=F#!
set Encrypted_Data=!Encrypted_Data:G=G#!
set Encrypted_Data=!Encrypted_Data:H=H#!
set Encrypted_Data=!Encrypted_Data:I=I#!
set Encrypted_Data=!Encrypted_Data:J=J#!
set Encrypted_Data=!Encrypted_Data:K=K#!
set Encrypted_Data=!Encrypted_Data:L=L#!
set Encrypted_Data=!Encrypted_Data:M=M#!
set Encrypted_Data=!Encrypted_Data:N=N#!
set Encrypted_Data=!Encrypted_Data:O=O#!
set Encrypted_Data=!Encrypted_Data:P=P#!
set Encrypted_Data=!Encrypted_Data:Q=Q#!
set Encrypted_Data=!Encrypted_Data:R=R#!
set Encrypted_Data=!Encrypted_Data:S=S#!
set Encrypted_Data=!Encrypted_Data:T=T#!
set Encrypted_Data=!Encrypted_Data:U=U#!
set Encrypted_Data=!Encrypted_Data:V=V#!
set Encrypted_Data=!Encrypted_Data:W=W#!
set Encrypted_Data=!Encrypted_Data:X=X#!
set Encrypted_Data=!Encrypted_Data:Y=Y#!
set Encrypted_Data=!Encrypted_Data:Z=Z#!
set Encrypted_Data=!Encrypted_Data:A#=N!
set Encrypted_Data=!Encrypted_Data:B#=O!
set Encrypted_Data=!Encrypted_Data:C#=P!
set Encrypted_Data=!Encrypted_Data:D#=Q!
set Encrypted_Data=!Encrypted_Data:E#=R!
set Encrypted_Data=!Encrypted_Data:F#=S!
set Encrypted_Data=!Encrypted_Data:G#=T!
set Encrypted_Data=!Encrypted_Data:H#=U!
set Encrypted_Data=!Encrypted_Data:I#=V!
set Encrypted_Data=!Encrypted_Data:J#=W!
set Encrypted_Data=!Encrypted_Data:K#=X!
set Encrypted_Data=!Encrypted_Data:L#=Y!
set Encrypted_Data=!Encrypted_Data:M#=Z!
set Encrypted_Data=!Encrypted_Data:N#=A!
set Encrypted_Data=!Encrypted_Data:O#=B!
set Encrypted_Data=!Encrypted_Data:P#=C!
set Encrypted_Data=!Encrypted_Data:Q#=D!
set Encrypted_Data=!Encrypted_Data:R#=E!
set Encrypted_Data=!Encrypted_Data:S#=F!
set Encrypted_Data=!Encrypted_Data:T#=G!
set Encrypted_Data=!Encrypted_Data:U#=H!
set Encrypted_Data=!Encrypted_Data:V#=I!
set Encrypted_Data=!Encrypted_Data:W#=J!
set Encrypted_Data=!Encrypted_Data:X#=K!
set Encrypted_Data=!Encrypted_Data:Y#=L!
set Encrypted_Data=!Encrypted_Data:Z#=M!
echo.
echo. Original Data:%data%
echo.
echo. Encrypted/Decrypted Data:%Encrypted_Data%
echo.
pause
As you can see, i use mapping method and It worked perfectly (Input=HELLO,Output=URYYB),But i realy it tiring to modify it one by one if Needed or to make it as micro.
But when i trying to Shorten the code by using Loop and using same method .
Sample.Bat:
@echo off & setlocal EnableDelayedExpansion
set "Data=HELLO"
set "Process=Rot13"
set "Rot13_input= ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "Rot13_output= NOPQRSTUVWXYZABCDEFGHIJKLM"
::set "xxxxxx_input= xxxxxxxxxxxxxxxxxxx"
::set "xxxxxx_output= xxxxxxxxxxxxxxxxxxx"
if %Process% equ Rot13 set "Maxdigit=27"
for /l %%n in (1,1,%Maxdigit%) do ^
set "%Process%_input_%%n=!Rot13_input:~%%n,1!" & ^
set "%Process%_output_%%n=!Rot13_output:~%%n,1!"
::set Rot13_input_
::set Rot13_output_
set Encrypted_Data=!Data!
:: STUCK BELOW ::
for /l %%n in (1,1,%Maxdigit%) do ^
set Encrypted_Data=!Encrypted_Data:%Rot13_input_%%n%=%Rot13_input_%%n%#!
echo %Encrypted_Data%
:: STUCK ABOVE ::
pause
echo.
echo. Original Data:%data%
echo.
echo. Encrypted/Decrypted Data:%Encrypted_Data%
echo.
pause
I am stuck(error output) at second LOOP,Can anyone fix this or Maybe another methods it can be done?
for /l %%n in (1,1,%Maxdigit%) do call set "Encrypted_Data=%%Encrypted_Data:!Rot13_input_%%n!=!Rot13_input_%%n!#%%"(this establishes 3 layers of variable expansion: 1. index%%n, 2. search and replace strings, 3. whole string)