China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 05:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch processing about encrypted documents View 1,827 Replies 7
Original Poster Posted 2010-06-19 23:39 ·  中国 安徽 安庆 电信
新手上路
Credits 5
Posts 5
Joined 2010-06-19 23:25
16-year member
UID 169176
Gender Male
Status Offline
Now I want to make a batch script to encrypt a document.

The working method is like this:
1. There is a text document a.txt
2. After processing by the batch script, generate *.bat * that is the file name and can be customized.
3. When opening this bat with Notepad, you can't see the content inside, that is, you can't 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 me if there is anything unclear in my intention.
Floor 2 Posted 2010-06-20 00:52 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Where did you see such a batch file?
Floor 3 Posted 2010-06-20 01:53 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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 ]
Floor 4 Posted 2010-06-20 13:03 ·  中国 安徽 安庆 电信
新手上路
Credits 5
Posts 5
Joined 2010-06-19 23:25
16-year member
UID 169176
Gender Male
Status Offline
I roughly wrote it out.

Now there's a problem:


:jm
type "%nfile%.bat" | echo @echo off>>"%nfile%.bat"
type "%nfile%.bat" | echo title Opening Encrypted Document: "file"...>>"%nfile%.bat"
type "%nfile%.bat" | echo color a2>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo :begin>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please enter the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can see the content of the text document after entering the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p mm= Enter password:>>"%nfile%.bat"
type "%nfile%.bat" | echo if not "%mm%"=="%password%" goto mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo goto xuanzefangshi>>"%nfile%.bat"
type "%nfile%.bat" | echo :mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Password incorrect!!! Please enter again! >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can see the content of the text document after entering the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p mm1= Re-enter password:>>"%nfile%.bat"
type "%nfile%.bat" | echo if not "%mm1%"=="%password%" goto mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo :xuanzefangshi
type "%nfile%.bat" | echo cls
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please select the way to open the text: >>"%nfile%.bat"
type "%nfile%.bat" | echo echo Open in this window.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Generate another new file %nfile%.txt>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p way= Select way:>>"%nfile%.bat"
type "%nfile%.bat" | echo if "%way%"=="1" goto zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo if "%way%"=="2" goto newtxt>>"%nfile%.bat"
type "%nfile%.bat" | echo :zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type %file%>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.
type "%nfile%.bat" | echo echo =======================end================================>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo If you want to copy, click right mouse button - Mark>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Select the content to be copied - right mouse button >>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can complete the copy.>>"%nfile%.bat"
type "%nfile%.bat" | echo :newtxt>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo File decryption completed!!>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please view the newly generated file %nfile%.txt>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Press any key to close...>>"%nfile%.bat"
type "%nfile%.bat" | echo pause>nul>>"%nfile%.bat"


In the above part, I want to embed %file% into %nfile%.bat
Then run %nfile%.bat
After entering the pre-set password and selecting the way,
%nfile%.bat can generate a new %file% or directly display the content of %file% in the cmd window
But I don't know how to do it


type "%nfile%.bat" | echo :zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type %file%>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.
type "%nfile%.bat" | echo echo =======================end================================>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo If you want to copy, click right mouse button - Mark>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Select the content to be copied - right mouse button >>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can complete the copy.>>"%nfile%.bat"


This part of type %file%>>"%nfile%.bat" doesn't seem to work well.

[ Last edited by doshhwa on 2010-6-20 at 13:08 ]
Floor 5 Posted 2010-06-20 13:34 ·  中国 安徽 安庆 电信
新手上路
Credits 5
Posts 5
Joined 2010-06-19 23:25
16-year member
UID 169176
Gender Male
Status Offline
Now the problem is simplified:

How to put the line if not "%mm%"=="%password%" goto mmcw into %nfile%.bat.

If you use type "%nfile%.bat" | echo if not "%mm%"=="%password%" goto mmcw>>"%nfile%.bat", the output will be:
if not ""=="asdf" goto mmcw (because password was defined as asdf earlier, so asdf will be displayed)

The complete code is:
@echo off
set /p file= File:
set /p nfile= New file:
set /p password= Password:
:jm
type "%nfile%.bat" | echo @echo off>>"%nfile%.bat"
type "%nfile%.bat" | echo title Opening encrypted document: "file"...>>"%nfile%.bat"
type "%nfile%.bat" | echo color a2>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo :begin>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please enter the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can see the content of the text document after entering the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p mm= Enter password:>>"%nfile%.bat"
type "%nfile%.bat" | echo if not "%mm%"=="%password%" goto mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo goto xuanzefangshi>>"%nfile%.bat"
type "%nfile%.bat" | echo :mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Password error!!! Please re-enter! >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can see the content of the text document after entering the password. >>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p mm= Re-enter password:>>"%nfile%.bat"
type "%nfile%.bat" | echo if not "%mm%"=="%password%" goto mmcw>>"%nfile%.bat"
type "%nfile%.bat" | echo :xuanzefangshi
type "%nfile%.bat" | echo cls
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please choose the way to open the text: >>"%nfile%.bat"
type "%nfile%.bat" | echo [1] Open in this window.>>"%nfile%.bat"
type "%nfile%.bat" | echo [2] Generate another new file %nfile%.txt>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo set /p way= Choose the way:>>"%nfile%.bat"
type "%nfile%.bat" | echo if "%way%"=="1" goto zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo if "%way%"=="2" goto newtxt>>"%nfile%.bat"
type "%nfile%.bat" | echo :zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | type %file%>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo =======================end================================>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo If you want to copy, click right mouse button - Mark>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Select the content to be copied - right mouse button >>"%nfile%.bat"
type "%nfile%.bat" | echo echo You can complete the copy.>>"%nfile%.bat"
type "%nfile%.bat" | echo :newtxt>>"%nfile%.bat"
type "%nfile%.bat" | echo cls>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┏ ┓>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo File decryption completed!!>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Please check the newly generated file %nfile%.txt>>"%nfile%.bat"
type "%nfile%.bat" | echo echo.>>"%nfile%.bat"
type "%nfile%.bat" | echo echo ┗ ┛>>"%nfile%.bat"
type "%nfile%.bat" | echo echo Any key to close...>>"%nfile%.bat"
type "%nfile%.bat" | echo pause>nul>>"%nfile%.bat"


Among them
type "%nfile%.bat" | echo if "%way%"=="1" goto zhijiedakai>>"%nfile%.bat"
type "%nfile%.bat" | echo if "%way%"=="2" goto newtxt>>"%nfile%.bat"
also has the same problem, there is no %way%... in the newly generated file
Floor 6 Posted 2010-06-20 14:32 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
I can't see the real encryption and decryption processes in your code.
Floor 7 Posted 2010-06-20 14:54 ·  中国 安徽 安庆 电信
新手上路
Credits 5
Posts 5
Joined 2010-06-19 23:25
16-year member
UID 169176
Gender Male
Status Offline
No, the encryption and decryption segments haven't been added yet.

I don't know how to input the line `if not "%mm%"=="%password%" goto mmcw` into `%nfile%.bat`.

If I use `type "%nfile%.bat" | echo if not "%mm%"=="%password%" goto mmcw>>"%nfile%.bat"`, the output will be:
if not ""=="asdf" goto mmcw (since password was defined as asdf earlier, so it will display asdf)
Floor 8 Posted 2010-12-28 10:32 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
Learning
Forum Jump: