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-21 07:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] [Discussion] Non-compiled Batch Processing Encryption Scheme and Code DigestI View 110,341 Replies 364
Floor 16 Posted 2006-07-21 17:23 ·  中国 福建 泉州 石狮市
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
The 7th floor is impressive. I'm not sure about the principle, but you can view it using the DOS TYPE command. Just avoid opening it with Windows Notepad.

It seems there isn't currently a software that can effectively encrypt .BAT files. Tools like QuickBFC.EXE merely package the BAT file; when run, they first extract the BAT file to a directory and then execute it.
QQ:366840202
http://chenall.net
Floor 17 Posted 2006-07-21 21:46 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
I don't understand the code in the 7th floor.

There seems to be a way to trick children: change the 0D 0A line breaks in the bat file to 0A, which may cause some trouble in reading.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 18 Posted 2006-07-22 01:18 ·  中国 北京 电信
初级用户
Credits 49
Posts 13
Joined 2006-07-13 11:21
19-year member
UID 58500
Status Offline
To restore an encrypted file, use Notepad and change the encoding format to "UTF-8" when saving. However, it is best to create a backup before encryption, as restoration may sometimes fail. Finally, thank you all for your support.
Floor 19 Posted 2006-07-22 08:54 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
The code on the 7th floor really does work for encryption. I don't know how it works; I can't figure it out, but I still want to give it a thumbs up. Impressive!

May I ask the 7th floor: Did you come up with this code yourself, or did you see it somewhere else? If you created it yourself, please explain the working principle. If you saw it elsewhere, that's fine. Thank you.

[ Last edited by bagpipe on 2006-7-22 at 08:55 ]
Floor 20 Posted 2006-07-22 11:03 ·  中国 北京 电信
初级用户
Credits 49
Posts 13
Joined 2006-07-13 11:21
19-year member
UID 58500
Status Offline
I can confirm that this method was not found elsewhere. In fact, I discovered this encryption technique quite by accident. As for the principle behind it, I suspect it is a bug in Windows, similar to how typing the word "联通" (without quotes) in Notepad and saving the file results in garbled text. You can try it to verify.
Floor 21 Posted 2006-07-22 12:47 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Why is the method on the 7th floor a one-time use? Does it not work the second time?
Floor 22 Posted 2006-07-22 16:08 ·  中国 广东 清远 联通
初级用户
Credits 62
Posts 25
Joined 2006-04-27 01:01
20-year member
UID 54520
Status Offline
Extend the index and middle fingers, separate them slightly at an angle of approximately 20 degrees, then insert, insert, insert... attacking the opponent's eyeballs^_^
Floor 23 Posted 2006-07-23 07:39 ·  中国 北京 电信
初级用户
Credits 49
Posts 13
Joined 2006-07-13 11:21
19-year member
UID 58500
Status Offline
The solution is to copy and paste the following code until the "encryption" result is successfully achieved. Everyone can try it! Thank you for your support!

for /l %%a in (1,1,10) do ren *.jpg %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a
Floor 24 Posted 2006-07-23 10:35 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Based on yuanyong630's description on the 18th floor, it seems that changing the encoding when saving the bat file in Notepad was used to achieve confidentiality. Why have none of my attempts succeeded? The system is XP+SP2.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 25 Posted 2006-07-23 12:15 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm & others:

Regarding Brother yuanyong630's encryption scheme, your思路 is correct, but there are slight deviations.

When the Notepad program saves a newly created document without a specified encoding type, it uses the default ANSI type (for the Chinese version, this corresponds to GB encoding).

When opening an existing document, it analyzes the document's encoding type. First, it checks for a BOM (Byte Order Mark, a 2-3 byte sequence) at the beginning of the document. If present, it determines the encoding type based on the content: FF FE (Unicode), FE FF (Unicode big endian), EF BB BF (UTF-8).

Since many non-ANSI encoded documents are "plain text" without any BOM, such documents cannot be simply judged as ANSI encoded. Instead, a series of statistical algorithms are used to guess the document encoding based on the content. Notepad uses the IsTextUnicode function to determine if the encoding is Unicode/Unicode big endian and IsTextUTF8 to check for UTF8 encoding.

However, as these are statistical algorithms, misjudgments are inevitable, especially when the document content is too short. Due to the small sample size, the probability of such misjudgments increases significantly. For example, the well-known joke about Microsoft having a grudge against China Unicom arises because Notepad misidentifies an ANSI encoded document containing only the two characters "联通" as UTF8 using the IsTextUTF8 function. Similar misjudgments occur with the IsTextUnicode function; for instance, a document with the structure "this app can break" (4335 structure) is misidentified as Unicode encoding.

It should be noted that such misjudgments are likely only when the text is short and its byte characteristics are not disturbed. If the text is slightly modified (even by adding a single carriage return), misjudgment becomes difficult.

The uniqueness of Brother yuanyong630's scheme lies in its byte string, which not only has Unicode characteristics but is also long, reaching 1288 bytes. This means its Unicode characteristics are strong, allowing it to resist interference from some short, non-Unicode characteristic strings, as determined by statistical laws. However, when the interfering string is somewhat longer, the Unicode characteristics will be significantly disrupted until the IsTextUnicode function identifies it as non-Unicode. Therefore, some friends who cannot successfully test it should consider the length and content of the additional batch processing code. Everyone can test the code in .

Other editors (such as Word/Wordpad/EditPlus/UltraEdit) use newer encoding determination algorithms, which have improved Unicode judgment, though UTF8 judgment remains unsatisfactory. Theoretically, a completely accurate algorithm does not exist, so we can only avoid using non-ANSI documents without BOM or manually specify the encoding type when opening documents.

Additionally, if Notepad is used to save files with misjudged encoding types, recovery becomes difficult. Saving with the misjudged encoding adds a BOM mark, making the original document unobservable in other editors. Saving with ANSI encoding converts the original document as if it were Unicode, leaving almost no possibility of restoration.

Unicode Introduction
http://my.opera.com/neutronstar/blog/index.dml/tag/编码

Why Does Microsoft Have a Grudge Against China Unicom
http://blog.vckbase.com/localvar/archive/2005/07/12/9510.aspx

Notepad bug? Encoding issue?
http://weblogs.asp.net/cumpsd/archive/2004/02/27/81098.aspx

Bush Hid The Facts
http://www.shoutwire.com/comments/16341/Bush_Hid_The_Facts

cry.cmd

for /l %%a in (1,1,10) do ren *.jpg %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a
@echo off
echo bbs.cn-dos.net
echo.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 26 Posted 2006-07-23 12:27 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re electronixtar(17):

Regarding the method of changing 0d 0a to 0a, it might be better to change it to 0d instead. That is, changing carriage return and line feed to only carriage return without line feed; then the text of the current line will be overwritten by the text line without line feed, and such overwriting and superimposition will repeat. If a comment text longer than all the above lines is added at the last line of the batch file, only such a comment will be displayed in the end.

This method is effective for EDIT and TYPE, so it was once popular during the DOS era. However, this solution is similar to Brother yuanyong630's solution; it only targets the specific text processing mechanism of specific text processors and cannot be applied to all platform environments.

As for other encryption methods, each has its own flaws, and it is relatively difficult to meet the requirements of software engineering.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 27 Posted 2006-07-23 13:24 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
First, thank you to yuanyong630 for providing the encryption code; I only used it to write this tool to facilitate everyone's use.

I have fixed the flaw in renaming image files as pointed out by the moderator, and now a total of four encryption methods are provided.

[ Last edited by pengfei on 2006-10-2 at 09:12 ]
Attachments
BAT加密工具.rar (978 bytes, Credits to download 1 pts, Downloads: 2056)
Floor 28 Posted 2006-07-23 13:43 ·  中国 辽宁 大连 教育网
中级用户
★★
DOS之友
Credits 332
Posts 168
Joined 2005-10-06 00:00
20-year member
UID 43171
Gender Male
From 天涯
Status Offline
Testing was unsuccessful on my end. Whether using method one or method two, the following code was added before my code:
for /l %%a in (1,1,10) do ren *.jpg %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a
测试环境: windows xp pro sp2 高手是这样炼成的:C:\WINDOWS\Help\ntcmds.chm
Floor 29 Posted 2006-07-23 13:58 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I tried it and found that only those starting with "@echo off" on the first line can be encrypted successfully, but not all of them. After encryption, opening it with Notepad shows garbled characters, but it can still be executed.

[ Last edited by zxcv on 2006-7-23 at 14:01 ]
Floor 30 Posted 2006-07-23 14:03 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
'lkj;l

[ Last edited by pengfei on 2007-1-22 at 10:43 AM ]
Forum Jump: