Anyway just thought I'd share - maybe someone will find it interesting / useable. I noticed that someone was making a password input prompt in their batch file anyway, maybe you could use it to encode the passwords or something, lol
code can only be 4 digits and is purely numerical (0 not advised as a digit)
encode example.bat:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set /p message=))
set /p code=Code:
call :encode string "%message%" "%code%"
echo %string%>message.txt
echo %string%
pause
goto :eof
:encode
rem Encodes a string using a code specified.
rem -Requires length function
rem -Requires genPage function
rem
rem Syntax: encode [rVar] "string" "code"
set "str=%~2"
set "str=%str: =_%"
set "rStr="
set "page=%temp%\code.tmp"
call :genPage "%page%" %~3
call :length len "%str%"
set /a len=len-1
for /l %%a in (0,1,%len%) do (
for /f "usebackq tokens=1,2 delims=;" %%b in (%page%) do (
if "!str:~%%a,1!"=="%%b" set "rStr=!rStr!%%c"
))
del /q "%page%"
endlocal & if not "%~1"=="" set %~1=%rStr% & exit /b
goto :eof
:length
rem Returns the length of a string.
rem
rem Syntax: length [rVar] "string"
setlocal enabledelayedexpansion
set "str=%~2"
set "len=0"
set "count=0"
:length_loop
if "!str:~%len%,1!"=="" (
endlocal & if not "%~1"=="" set %~1=%len% & exit /b
) else set /a len=len+1
goto :length_loop
:genPage
rem Generates a codepage for use encoding / decoding text.
rem based on a 4 digit code.
rem -Requires length function
rem
rem Syntax: genPage "page name" [code]
setlocal enabledelayedexpansion
set "file=%~1"
set "code=%~2"
set "s1=%code:~0,1%"
set "s2=%code:~1,1%"
set "s3=%code:~2,1%"
set "s4=%code:~3,1%"
set "list=._!?/,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$"
set "letter=."
set "str=%str: =.%"
for /l %%a in (0,1,%s1%) do (
for /l %%b in (0,1,%s2%) do (
for /l %%c in (0,1,%s3%) do (
for /l %%d in (0,1,%s4%) do (
call :nextLetter
echo !letter!;%%a%%b%%c%%d>>%file%
if not defined letter goto :eof
))))
endlocal
exit /b
:nextLetter
for /l %%a in (0,1,69) do if "!list:~%%a,1!"=="!letter!" set /a next=%%a+1 & set "letter=!list:~%next%,1!"
goto :eof
note - the encoded text is saved in a file called message.txt and read into decode.bat automatically so the user doesn't have to type the encoded text into the decode.bat prompt