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-22 21:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Text Encryption and Decryption Program (bat + debug) DigestI View 15,917 Replies 23
Original Poster Posted 2007-05-30 15:42 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Last night someone posted a VB text encryption program
Using the Caesar cipher of adding 1 to each byte
Soon our moderator brother made a VBS version
Remembering that such simple text processing is more lightweight in assembly
But I was hot and sleepy yesterday, so I didn't code it
Today there was a moderate rain and it became much cooler
Although I was nervous and busy
But I still took the time to write it
To prevent forgetting it when the weather gets hot again tomorrow
-------------------------------------------------------

At first I planned to fully implement the +1/-1 cipher
Later considering to benefit our lazy people
I thought that XOR is simpler and more practical
+1 is too easy to guess, I once broke the encrypted code after +1 of a certain bat2exe program
The XOR algorithm is relatively harder to guess
And encryption/decryption can reuse a module
Originally wanted to support multi-bit keys
So that it is more practical
But unfortunately, whether +1 or +X or XOR X may get FF
And FF cannot be output to standard output
For the sake of simple code
Still used the scheme of XOR with E0~EF
So only the bytes from 10~1F may get FF
And this area are control characters
Rarely used in text files
------------------------------------------------------

Due to time constraints
No special circumstances
Not going to update it
Those interested can study it by themselves



@echo off & setlocal & chcp 437>nul & graftabl 936>nul

if "%~1"=="" (
echo.
echo.=Text File Encryption/Decryption Program :: qzwqzw :: 2007-06-05 :: Release 7
echo.
echo.=Principle: Dynamically generate an executable program using DEBUG script to XOR each byte of the input file
echo.
echo.=Features: Encryption and decryption are reciprocal, multi-file operation, single-digit key
echo.
set /p file=-Please enter the file name (supports wildcards, default is .\*.txt):
set /p pass=-Please enter the key (a hexadecimal number from 0~F, default is 0):
echo.
) else (
set "file=%~1"
set "pass=%~2"
)

if "%file%"=="" set file=*.txt
if "%pass%"=="" set pass=0
if not exist "%file%" echo !File not found: "%file%" && goto end

:: Generate and execute DEBUG script to generate conversion program
echo e 100 B4 06 B2 FF CD 21 74 08 34 E%pass% 88 C2 CD 21 EB F0 C3>_codec.scr
for %%s in (rcx 11 n_codec.com w q) do echo %%s>>_codec.scr
debug <_codec.scr | find "Error">nul && echo !Key error: "%pass%" && goto :end

:: Search for all matching files in the specified path for conversion
for %%f in ("%file%") do set "fPath=%%~dpf"
for /f "delims=" %%f in ('dir /a/b/od "%file%" 2^>nul') do (
(set "fIn=%fPath%%%f") && (set "fOut=%fPath%#%%f")
call :Codec
)
echo.
if exist _codec.* del _codec.*
if "%~0"=="%~f0" pause
goto :eof

:Codec
if exist "%fOut%" echo !File already exists: "%fOut%" && pause && goto :eof
echo +Converting "%fIn%" ...
if exist _codec.com _codec.com < "%fIn%" > "%fOut%"
if not exist "%fOut%" echo !Conversion failed, "%fOut%" not generated && pause


[ Last edited by qzwqzw on 2007-6-5 at 12:09 PM ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
youxi01 +8 2007-05-30 15:58
namejm +10 2007-05-30 21:35
electronixtar +22 2007-12-06 14:44
Floor 2 Posted 2007-05-30 16:12 ·  中国 山东 济南 联通
新手上路
Credits 10
Posts 5
Joined 2007-05-28 05:02
19-year member
UID 89525
Gender Male
Status Offline
Is this kind of program useful?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
slndx +1 2008-03-23 17:30
Floor 3 Posted 2007-05-30 16:20 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
First, a preliminary test was carried out, and the following two problems were discovered:

When the path contains spaces, there will be no result. The problem lies in the sentence "if exist _codec.com %comspec% /c_codec < %file% > %file%.txt". The relevant "%file%" statement should be enclosed in quotation marks;

In addition, there is a logical problem in the first two pairs of if statements: when file or pass is not defined, default values are forcibly assigned to them, resulting in the fact that the latter two set /p statements have no chance to be executed at all.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 4 Posted 2007-05-30 18:31 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Hi, said not to update
But there are really too many problems
So had to release a new version
To avoid leading people astray

In addition, some details are modified and added
Such as the default value for operating files
For example, operation prompts and code comments
Floor 5 Posted 2007-05-30 21:34 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, it seems that brother qzwqzw wants to be lazy and doesn't plan to update anymore? Then I'll pick some more flaws:

1. The /s parameter is added to dir, which is bound to search in all subdirectories. If the specified file with the same name exists in the current directory and several subdirectories, the operation of the specified file will become difficult to control. It is suggested to not search subdirectories when searching for files;

2. The operation of adding quotes to the file path is incomplete, and there are still fish that slip through the net. For example, set file=%~dp0\*.txt. If there is & in this path, it will still go wrong.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2007-05-30 22:42 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Originally, the /s parameter was not added.
Later, it was found that when directly dragging the test file to the program, the current directory turned out to be %userprofile%.
Then using ~ff would cause problems.
So /s was added to get the full path.
Now it seems that adding it is quite problematic.

The issue with set file=
Actually, you considered it meticulously.
But there are too many such problems.
I have already become tired of it.
Floor 7 Posted 2007-05-30 23:56 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Endure it for the sake of the person who gives extra points

The /s is removed, and the method of first obtaining the data file directory and then piecing together the path is changed

set file has been changed as much as possible

Anyone who is free can test it

Drag and drop the data file to the program
Drag and drop the data file to the command line window
Enter the file path to the command line window

The file path contains spaces
The file path contains escape characters
The file path is invalid
Floor 8 Posted 2007-05-31 00:13 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, I really found a problem, but it's still the old issue: not enclosing all paths in quotes - although the buddy is a bit tired of this problem, but I still have to mention it ^_^

The problem is in this line: set file=%1. When I handle the file te st.txt in the format of "*test.cmd" "te st.txt" in the CMD window... Hehe, you understand without me saying. It is suggested to change it to set "file=%~1".

I haven't had time to test other things for the time being.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2007-05-31 00:45 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
This problem has been modified.

By the way, the conditions for the appearance of the program logo have been modified.

Also, a simple modification of the prompt.
-------------------------------------------------------------------

Now I formally authorize this code to the China DOS Union.

All members of the union can copy, modify and republish it.

They can also use all or part of the code as part of their own code or project.

Any project or code that uses this code must not violate the principle of free and open code.

It cannot be used for any commercial or profit-making purposes.

In short, it is released under a streamlined GPL agreement.

That is to say, any further problems need you to modify them by yourselves.

Absolutely a lazy person's agreement
Floor 10 Posted 2007-08-01 04:46 ·  中国 湖北 武汉 电信
新手上路
Credits 10
Posts 5
Joined 2007-08-01 04:09
18-year member
UID 94410
Gender Male
Status Offline
Thanks for your sharing and testing. I'm a new user and think such an atmosphere is very good.
Floor 11 Posted 2007-08-01 12:21 ·  中国 浙江 宁波 余姚市 电信
初级用户
Credits 83
Posts 34
Joined 2007-04-22 23:47
19-year member
UID 86116
Gender Male
Status Offline
Well, I also think this place is good
快乐崇拜
Floor 12 Posted 2007-08-03 07:36 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
19-year member
UID 59720
Status Offline
I tried it initially, and the effect is good. It can also be encrypted multiple times. But it is not available for text programs (bat com).
Floor 13 Posted 2007-08-05 16:31 ·  中国 甘肃 天水 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
I can't understand debug, ai
Floor 14 Posted 2007-08-06 10:00 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
I wrote something encrypted using the %XXXX:~X,X% method before... But... After encryption, it's 5 to 10 times larger than the original file...
Floor 15 Posted 2007-08-19 09:41 ·  中国 浙江 嘉兴 桐乡市 电信
初级用户
Credits 20
Posts 8
Joined 2007-08-05 07:19
18-year member
UID 94663
Gender Male
Status Offline
Almost all can't understand, who can explain the principle?
Forum Jump: