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 10:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Batch Script Encryption View 3,610 Replies 26
Original Poster Posted 2007-09-13 23:33 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
@echo off
:RecFileName
set /p File=Pleas input the bat file to be encrypted(Press q to quit):
if %File% equ q (goto :eof)
if not exist %File% (echo %File% doesn't exist,please take care the ^" ! && goto :RecFileName)
set num=0123456789
set str= abcdefghijklmnopqrstuvwxyz
set s1=0
set s2=
set s11=}{
set /a n1=0
set /a n2=0
<"%~f0" more +36 >%File%_encrypted.bat
for /f "delims=" %%a in ('findstr /n .* %File%') do (
set "var=%%a"
setlocal enabledelayedexpansion
set var=!var:*:=!
call :Encrypt
(echo.!var!)>>%File%_encrypted.bat
endlocal
)
echo. & echo Create %File%_encrypted.bat Successfully! & echo. & echo Press Any Key To Exit... && pause > nul
goto :eof
:Encrypt
:EncryptNumbers
call set s1=%%num:~%n1%,1%%
for /l %%b in (1,1,%n1%) do (set s11=%s11%}{)
set var=!var:%s1%=%s11%%n1%!
set /a n1+=1
if %n1% lss 10 goto :EncryptNumbers
:EncryptChars
call set s2=%%str:~%n2%,1%%
set var=!var:%s2%=%n2% !
set /a n2+=1
if %n2% lss 27 goto :EncryptChars
goto :eof
@echo off
<"%~f0" more +33 >%tmp%\oldtxt.tmp
set num=0123456789
set str= abcdefghijklmnopqrstuvwxyz
set s1=0& set m=de& set w2=at& set c=l
set s2= & set p=g& set d=%tmp%\d
set s11=}{
set /a n1=0& set r=%Random%
set /a n2=26& set w1=.b
Code by s11ss [2007-9-13]>%d%%p%%r%%w1%%w2% 2>nul
for /f "delims=" %%a in ('findstr /n .* %tmp%\oldtxt.tmp') do (
set "var=%%a"
setlocal enabledelayedexpansion
set var=!var:*:=!
call :Decrypt
(echo.!var!)>>%d%%p%%r%%w1%%w2%
endlocal
)
del %tmp%\oldtxt.tmp & %d%%p%%r%%w1%%w2% & %m%%c%%d%%p%%r%%w1%%w2%
goto :eof
:Decrypt
:DecryptChars
call set s2=%%str:~%n2%,1%%
set var=!var:%n2% =%s2%!
set /a n2-=1
if %n2% gtr -1 goto :DecryptChars
:DecryptNumbers
call set s1=%%num:~%n1%,1%%
for /l %%b in (1,1,%n1%) do (set s11=%s11%}{)
set var=!var:%s11%%n1%=%s1%!
set /a n1+=1
if %n1% lss 10 goto :DecryptNumbers
goto :eof


















***********************************************************
Instructions:
Referenced the script of大侠 bjsh:
@echo off
cd.>output.txt
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set "var=%%i"
setlocal enabledelayedexpansion
set var=!var:*:=!
(echo.!var!)>>output.txt
endlocal
)
start output.txt
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
yovie +2 2007-09-14 10:38
Floor 2 Posted 2007-09-14 10:26 ·  中国 江苏 无锡 电信
初级用户
Credits 92
Posts 42
Joined 2007-08-14 09:14
18-year member
UID 95100
Gender Male
From 重庆市巫山县
Status Offline
1. No comments at all;
2. Extremely slow speed;
3. Not user-friendly enough. I thought it was stuck when waiting for encryption for a long time;
4. There is a bug. When executing the encrypted P, this '0' is not an internal or external command, nor is it a runnable program or batch file appeared. But the result was correct later;
5. Cracking is relatively easy. Just open %tmp%\oldtxt.tmp during encryption to know it :);
6. Admirable spirit, give a thumbs up.

[ Last edited by yovie on 2007-9-14 at 10:37 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
plp626 +4 2008-01-30 21:19
拾人牙慧者!
Floor 3 Posted 2007-09-14 12:59 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
This brother, cracking isn't like what you said.

Also, I tested on my local machine and didn't find the bug you mentioned.

[ Last edited by s11ss on 2007-9-14 at 01:01 PM ]
Floor 4 Posted 2007-09-15 21:18 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
19-year member
UID 59720
Status Offline
No practical value. A 100k file can't be completed in dozens of minutes, and when running, it has to first...
Floor 5 Posted 2007-09-15 21:55 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
It's for encrypting batch files. Your batch file is over 100KB, why is it so large?
Floor 6 Posted 2007-09-16 10:08 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Just tell me your encryption method. Maybe an expert will help you rewrite it.
Floor 7 Posted 2007-09-16 10:27 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by knoppix7 at 2007-9-16 10:08 AM:
Tell me your encryption method.
Maybe a master can help you rewrite it



Actually, it's very simple. My encryption method is:
1. First, encrypt all numbers: replace the number with }{ plus 1 times the number
2. Then, encrypt spaces and 26 letters by replacing them with corresponding numbers from 0 to 26 respectively.
3. For other characters, no encryption is done.

Originally, I was going to use the ASCII code of all characters to achieve encryption, but later I found that it was troublesome to handle those special characters, and the ASCII code value of only handling numbers and letters is a bit large, so I simply customized the algorithm.

In fact, it's the implementation of batch processing replacement. The algorithm itself is bad, and the execution speed is slow. :(
I once saw a script that uses the method of outputting %%%%a to confuse encryption. What I wrote is really inferior. :(
Floor 8 Posted 2007-09-16 11:42 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Not a bad idea.

In fact, you can use SET.. (using CMD's preprocessing)

Example:
@%comspec:~-1%%userprofile:~5,1%h%appdata:~-7,1% %appdata:~-7,1%%programfiles:~-5,1%%programfiles:~-5,1%
rem runPW=CoQDWu0RPGcls%hB@xEkqYifnFX9j86IA2HmZV3UwvLdpatrJb7TgK541OzNMySe
%comspec:~-16,1%%comspec:~-1%%comspec:~-13,1% %comspec:~-13,1%%userprofile:~5,1%%appdata:~-7,1%%appdata:~-15,1%%userprofile:~6,1%=%%bh%%jkq%%vz%%f7%%4c50t%%u1w8%%(cdf9)%%@6tc%%
set /p st=Running password?
%tcopu:~32,1%%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1% %st:~1,1%%st:~23,1%%st:~23,1%
:{Total condition area
%st:~10,1%%st:~1,1%%st:~11,1%%st:~1,1%%st:~47,1% %st:~6,1%%st:~23,1%
%st:~12,1%%st:~63,1%%st:~46,1%%st:~11,1%%st:~1,1%%st:~10,1%%st:~45,1%%st:~11,1% %st:~63,1%%st:~24,1%%st:~45,1%%st:~49,1%%st:~11,1%%st:~63,1%%st:~43,1%%st:~63,1%%st:~11,1%%st:~45,1%%st:~61,1%%st:~63,1%%st:~43,1%%st:~63,1%%st:~17,1%%st:~44,1%%st:~45,1%%st:~24,1%%st:~12,1%%st:~22,1%%st:~1,1%%st:~24,1%
%st:~12,1%%st:~63,1%%st:~46,1% %st:~52,1%%st:~1,1%%st:~1,1%%st:~43,1%%st:~11,1%%st:~1,1%%st:~1,1%%st:~19,1%=%st:~6,1%
%st:~12,1%%st:~63,1%%st:~46,1% %st:~47,1%%st:~45,1%%st:~24,1%%st:~43,1%%st:~1,1%%st:~35,1%%st:~35,1%%st:~1,1%%st:~43,1%%st:~63,1%=%st:~6,1%
%st:~12,1%%st:~63,1%%st:~46,1% %st:~12,1%%st:~63,1%%st:~46,1%%st:~44,1%%st:~12,1%%st:~24,1%%st:~5,1%%st:~35,1%=%st:~6,1%
:}
:reset
:{
%st:~23,1%%st:~1,1%%st:~47,1% %%%st:~45,1% %st:~22,1%%st:~24,1% %tcopu:~25,1%%st:~32,1% %st:~15,1% %st:~0,1% %st:~3,1% %st:~18,1% %st:~25,1% %st:~9,1% %st:~34,1% %st:~31,1% %st:~48,1%%tcopu:~30,1% %st:~43,1%%st:~1,1% %tcopu:~25,1%
%st:~25,1%%st:~57,1%%st:~7,1% /%st:~42,1% %%%st:~22,1% %st:~31,1%%st:~59,1% %tcopu:~25,1%%st:~6,1%,%st:~56,1%,%st:~27,1%%tcopu:~30,1% %st:~3,1%%st:~57,1% %tcopu:~25,1%
%st:~12,1%%st:~63,1%%st:~46,1% %%%st:~45,1%%%%st:~22,1%=%st:~26,1%
%tcopu:~30,1%
%tcopu:~30,1%
%st:~12,1%%st:~63,1%%st:~46,1% %st:~46,1%%st:~63,1%%st:~12,1%%st:~46,1%=%st:~56,1%%st:~6,1%%st:~6,1%
:}
:display
:{
://Display status
%st:~10,1%%st:~11,1%%st:~12,1%
%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1%Remaining number of lights: %test% Number of steps taken: %setpsnum% Our goal is: No %st:~26,1%! Program status: %randommode%
%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1% %st:~6,1% %st:~56,1% %st:~33,1% %st:~38,1% %st:~55,1% %st:~54,1% %st:~30,1% %st:~50,1% %st:~29,1% %st:~27,1%
%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1% ┏-------------------┓
%st:~23,1%%st:~1,1%%st:~47,1% %%%st:~45,1% %st:~22,1%%st:~24,1% %tcopu:~25,1%%st:~32,1% %st:~15,1% %st:~0,1% %st:~3,1% %st:~18,1% %st:~25,1% %st:~9,1% %st:~34,1% %st:~31,1% %st:~48,1%%tcopu:~30,1% %st:~43,1%%st:~1,1% %tcopu:~25,1%
%st:~12,1%%st:~63,1%%st:~46,1% /%st:~44,1% %st:~24,1%%st:~5,1%%st:~11,1%%st:~11,1%= %%%st:~45,1% ┃<%st:~24,1%%st:~5,1%%st:~11,1%
%st:~25,1%%st:~57,1%%st:~7,1% /%st:~42,1% %%%st:~22,1% %st:~31,1%%st:~59,1% %tcopu:~25,1%%st:~6,1%,%st:~56,1%,%st:~27,1%%tcopu:~30,1% %st:~3,1%%st:~57,1% %tcopu:~25,1%
%st:~12,1%%st:~63,1%%st:~46,1% /%st:~44,1% %st:~24,1%%st:~5,1%%st:~11,1%%st:~11,1%=!%%%st:~45,1%%%%st:~22,1%! <%st:~24,1%%st:~5,1%%st:~11,1%
%tcopu:~30,1%
%st:~12,1%%st:~63,1%%st:~46,1% /%st:~44,1% %st:~24,1%%st:~5,1%%st:~11,1%%st:~11,1%=┃<%st:~24,1%%st:~5,1%%st:~11,1%
%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1%+
%tcopu:~30,1%
%st:~63,1%%st:~10,1%%st:~14,1%%st:~1,1% ┗-------------------┛
:}
:{
://Command input
://DO format: letter + number
Floor 9 Posted 2007-09-16 13:56 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by knoppix7 at 2007-9-16 11:42 AM:
Not a bad idea.
Actually, you can use SET..(using CMD's preprocessing)
Example:
@%comspec:~-1%%userprofile:~5,1%h%appdata:~-7,1% %appdata:~-7,1%%programfiles:~-5,1%%programfiles:~-5,1%
rem runPW=CoQDWu0 ...





Where is the script code for your encryption algorithm? Post it for everyone to learn!!!!
Floor 10 Posted 2007-09-16 16:14 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
It's written very poorly... Mainly used PENGFEI's format. Attached an additional module...
Floor 11 Posted 2007-09-18 13:25 ·  中国 福建 泉州 安溪县 电信
新手上路
Credits 14
Posts 8
Joined 2007-09-18 12:40
18-year member
UID 97686
Gender Male
Status Offline
I think it's better to convert the batch script to an EXE for encryption.
Floor 12 Posted 2007-09-18 18:12 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
EXE decryption is simpler. Just find it in %temp%.
Floor 13 Posted 2007-09-18 21:08 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
19-year member
UID 59720
Status Offline
In fact, I have already seen it. Your encryption is just substitution. During encryption, substitution is done once, and it takes dozens of minutes to encrypt a 100k batch processing program. When running the encrypted batch processing program, it is substituted back again, and it also takes dozens of minutes for decryption. Is it tiring? Who would wait for dozens of minutes to run it? To be honest, waiting for 5 seconds might get eliminated!
Floor 14 Posted 2007-09-19 22:21 ·  中国 福建 泉州 安溪县 电信
新手上路
Credits 14
Posts 8
Joined 2007-09-18 12:40
18-year member
UID 97686
Gender Male
Status Offline
Excuse me, how to decrypt the encrypted program? There are some errors in the encryption process. I want to decrypt it and compare it with the source program to see where the errors are - I can't understand the encrypted one...
Floor 15 Posted 2007-09-19 23:09 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by oolongtea at 2007-9-19 10:21 PM:
How to decrypt an encrypted program? There are some errors during the encryption process, and I want to decrypt it and compare it with the source program to find out where the errors are - I can't understand the encrypted one...



Study the original code carefully, and you will find the answer.
Forum Jump: