Originally posted by doshhwa at 2010-6-19 23:39:
Now I want to make a batch script to encrypt a document.
The working method is as follows:
1. There is a text document a.txt
2. After processing by the batch script, generate a *.bat * which is the file name and can be customized.
3. Opening this bat with Notepad cannot see the content inside, that is, cannot see the content of the text document a.txt
4. Running this bat prompts to enter the password set when the batch script is set.
5. After the password is passed, the content of the text document a.txt is displayed in the cmd window.
Now I don't know how to insert the content of the txt file into a batch script.
Please ask experts for advice!
If there is any unclear place in my intention, you can ask me.
Drag a.txt to this batch script to start running, and the password must be any permutation of 1234567890ABCDEF. The generated new batch script is the original name plus an underscore such as a_bat. Running the encrypted batch script generates a new text as Hanye.txt
@echo off&setlocal ENABLEDELAYEDEXPANSION
cd/d "%~dp0">nul
if %~z1 gtr 65280 echo. File size exceeds the range and an error occurs&pause&exit
copy/b "%~1" $tmp$>nul
set/a s=%~z1+255
set q=123456789ABCDEF0
set/p p=Please set the password:
for /l %%a in (0,1,15) do set "#!p:~%%a,1!=!q:~%%a,1!"
call:n %s%
(for /f "delims=" %%a in ('more +29^<%~fs0') do echo.%%a)>"%~n1_.bat"
(for /f "eol=- skip=1 delims=" %%a in ('^(echo d100,%s%^&echo q^)^|debug $tmp$^&^&del $tmp$') do (
set a=%%a&set a=!a:-= !
set/p=e!a:~5,6!<nul&set a=!a:~11,47!
for /l %%b in (0,1,46) do if "!a:~%%b,1!"==" " (set/p= <nul) else for %%c in (!a:~%%b^,1!) do set/p=!#%%c!<nul
echo.
))>>"%~n1_.bat"
graftabl 936 >nul
call:n %~z1
(for %%a in (rcx %s% nHanye.txt w q) do echo.%%a)>>"%~n1_.bat"
exit
:n
set n=%1&set s=
:m
set/a m=%n%%%16-1
set/a n/=16
set m=!q:~%m%,1!
set s=%m%%s%
if "%n%" neq "0" goto:m
goto:eof
@echo off&setlocal enabledelayedexpansion
set q=!q!
set/p p=Please enter the password:
for /l %%a in (0,1,15) do set "#^!q:~%%a,1^!=^!p:~%%a,1^!"
(for /f "delims=" %%a in ('more +15^<%~fs0') do (
set k=%%a&if not "^!k:~0,1^!"=="e" (echo.%%a) else (
set/p=^!k:~0,7^!<nul&set k=^!k:~7^!
for /l %%b in (0,1,46) do if "^!k:~%%b,1^!"==" " (set/p= <nul) else for %%c in (^!k:~%%b^^,1^!) do set/p=^!#%%c^!<nul
echo.
)
))>$tmp$
debug<$tmp$>nul
del /q $tmp$
graftabl 936 >nul
start "" Hanye.txt&exit
For example, the text content is "Cold Night Lone Star", the password is "A197D8E5F6C320B4", and the generated batch script is as follows:
@echo off&setlocal enabledelayedexpansion
set q=123456789ABCDEF0
set/p p=Please enter the password:
for /l %%a in (0,1,15) do set "#!q:~%%a,1!=!p:~%%a,1!"
(for /f "delims=" %%a in ('more +15^<%~fs0') do (
set k=%%a&if not "!k:~0,1!"=="e" (echo.%%a) else (
set/p=!k:~0,7!<nul&set k=!k:~7!
for /l %%b in (0,1,46) do if "!k:~%%b,1!"==" " (set/p= <nul) else for %%c in (!k:~%%b^,1!) do set/p=!#%%c!<nul
echo.
)
))>$tmp$
debug<$tmp$>nul
del /q $tmp$
graftabl 936 >nul
start "" Hanye.txt&exit
e0100 F1 17 5D F3 F3 BD 5E B4
rcx
8
nHanye.txt
w
q
[
Last edited by Hanyeguxing on 2010-6-20 at 02:02 ]