how to encrypt a text file using batch?

Viewed 14044

How can i encrypt the content in a text file using batch? and how can i decrypt it?

i have tried setting each letter to a number but i do not know how to split the string into each letter and do that.

I watched a video on youtube that help turn letters into numbers but it did not do it with a file.

this is the code he provides in the video.

@echo off
setlocal enableDelayedExpansion

set /p code=Text:
set chars=0123456789abcdefghijklmnopqrstuvwxyz

for /L %%N in (10 1 36) do (

for /F %%C in ("!chars:~%%N,1!") do (

set "code=!code:%%C=%%N!"

)

)

echo !code! 
pause

Please help Thank you

2 Answers
@echo off
setlocal enableDelayedExpansion

for /f "tokens=* delims= " %%h in ('type %1') do (
set text=%%h 
)

set chars=0123456789abcdefghijklmnopqrstuvwxyz

for /L %%N in (10 1 36) do (

for /F %%C in ("!chars:~%%N,1!") do (

set "text=!text:%%C=-%%N!"

)

)

echo !text! > %userprofile%\Desktop\encrypted.txt
pause


(using a different .bat file)

@echo off
setlocal enableDelayedExpansion

for /f "tokens=* delims= " %%h in ('type %1') do (
set text=%%h 
)

set chars=0123456789abcdefghijklmnopqrstuvwxyz

for /L %%N in (10 1 36) do (

for /F %%C in ("!chars:~%%N,1!") do (

set "text=!text:%%N=%%C!"

)

)

for /f %%K in ("!text!") do (
set "text=!text:-=!"
)

echo !text! > %userprofile%\Desktop\decrypted.txt
pause

Related