|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
不是 加密 ,是编码/解码。用纯文本来传输二进制文件的方法——Base64
It's not encryption, but encoding/decoding. The method to transmit binary files with plain text—Base64
|

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'>" |
|
2006-11-18 02:29 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
牛人还真是多呀,努力!
There are really many talented people, keep it up!
|

for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul |
|
2006-11-23 04:51 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
electronixtar 兄发的关于base64的第一个批处理基本看懂了,但是第二个怎么也搞不懂,严重打击了自信心,汗一个先。
Brother electronixtar's first batch processing about base64 is basically understood, but the second one can't be understood at all, which seriously hit the self-confidence, sweat one first.
|
|
2006-11-23 05:20 |
|
|
tao0610
高级用户
    朦胧的世界
积分 579
发帖 218
注册 2006-10-24
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
位运算反向倒回去果然复杂。
Bitwise operations reversed are indeed complicated.
|

认识自己,降伏自己,改变自己,才能改变别人! |
|
2006-11-23 06:06 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
精彩的好贴,欣赏~:)
Wonderful and great post, appreciate it~ :)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-25 03:05 |
|
|
zqygsd
新手上路

积分 4
发帖 2
注册 2006-12-20
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
泡妞密文一定要好好看看。。。
哈哈 !!
Must take a good look at the pick-up lines...
Haha!!
|
|
2006-12-20 23:04 |
|
|
vptdosme
初级用户
 
积分 97
发帖 32
注册 2005-12-3
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
此时不应有 ]==[0]。
At this time there should not be ]==.
|
|
2006-12-23 07:49 |
|
|
0401
中级用户
   带走
积分 435
发帖 88
注册 2005-9-24
状态 离线
|
  『第 23 楼』:
使用 LLM 解释/回答一下
发个编码解码的例子,局限性很大。因为我不知道如何将解码后的数转换为原来的字符。这个例子只是简单地通过查表来确定几个字符数字,像汉字就没办法了。还有就是我不懂怎么处理特殊字符,所以会出现很多错误的地方(当然是含有特殊字符的时候了。)
如果生成文件时用echo应该可以减少些特殊字符输入时的错误,但却还要判断0D0A(回车换行)这两个数,晕啊,随便了。
::code by 0401
@echo off
setlocal
set ASCII= !"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~
setlocal enabledelayedexpansion
set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set str=
set/p "str=请输入需要编码的字符串:"
if not defined str exit/b
call :enc
call :dec
exit/b
:enc
rem 两个比较的文件名为:
rem 将字符串放到文件中等待比较(fc)并求字符串长度
set/p=%str%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo 原始字符串长度为: %strlen% 字节
rem 生成fc用来与字符串比较的文件
for /l %%l in (0,1,%strlen%) do >>.cmp set/p= <nul
rem 将比较后得到的字符串的16进制存储到变量
for /f "tokens=3" %%i in ('fc/b .cmp .str^|find "A1"') do (set strhex=!strhex!%%i)
del .cmp .str
echo 转换后的16进制为: %strhex%
:encloop
if not defined strhex goto :encbreak
set chr1=0x!strhex:~0,2!
set chr2=0x!strhex:~2,2!
set chr3=0x!strhex:~4,2!
set strhex=%strhex:~6%
for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
set/a enc1=%chr1%">>"2
set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
set/a enc4=%chr3%"&"63
::echo 移位后得到的数据:%enc1% %enc2% %enc3% %enc4%
if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
::echo 移位后的数据编码为:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
goto :encloop
:encbreak
echo 字符串编码后的数据为
goto :eof
:dec
rem 并求编码字符串长度
set/p=%encstr%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo 编码后的字符串长度为: %strlen% 字节
del .str
rem 从编码的字符串encstr中求出编码时偏移的数量
set str=
for /l %%l in (0,1,%strlen%) do (
for /l %%m in (0,1,64) do (
if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
set str=!str!/%%m
)
)
)
set a=1&set b=4
:decloop
if %strlen% equ 0 goto :decbreak
for /f "tokens=%a%-%b% delims=/" %%i in ("%str%") do set enc1=%%i&set enc2=%%j&set enc3=%%k&set enc4=%%l
::echo 4个字节的偏移分别为: %enc1% %enc2% %enc3% %enc4%
set/a a+=4&set/a b+=4
set/a strlen-=4
set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))-32
set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))-32
set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)-32
::echo 4个字节解码后再减去32得到的十进制为: %chr1% %chr2% %chr3%
if %enc4% equ 64 if %enc3% equ 64 (set chr3=107&set chr2=107) else (set chr3=107)
::echo 解码后的数据为:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
set decstr=!decstr!!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
goto :decloop
:decbreak
echo 编码的数据解码后为
goto :eof
Post an example of encoding and decoding, which has great limitations. Because I don't know how to convert the decoded numbers back to the original characters. This example simply determines a few character numbers by looking up a table, and Chinese characters are not possible. Also, I don't know how to handle special characters, so there will be many errors when there are special characters (of course, when there are special characters).
If using echo when generating a file, it can reduce some errors when inputting special characters, but it still has to judge the two numbers 0D0A (carriage return and line feed), whatever.
::code by 0401
@echo off
setlocal
set ASCII= !"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~
setlocal enabledelayedexpansion
set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set str=
set/p "str=Please enter the string to be encoded: "
if not defined str exit/b
call :enc
call :dec
exit/b
:enc
rem The two file names for comparison are:
rem Put the string in a file for comparison (fc) and find the length of the string
set/p=%str%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo The length of the original string is: %strlen% bytes
rem Generate the file for fc to compare with the string
for /l %%l in (0,1,%strlen%) do >>.cmp set/p= <nul
rem Store the 16进制 of the compared string into a variable
for /f "tokens=3" %%i in ('fc/b .cmp .str^|find "A1"') do (set strhex=!strhex!%%i)
del .cmp .str
echo The converted hexadecimal is: %strhex%
:encloop
if not defined strhex goto :encbreak
set chr1=0x!strhex:~0,2!
set chr2=0x!strhex:~2,2!
set chr3=0x!strhex:~4,2!
set strhex=%strhex:~6%
for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
set/a enc1=%chr1%">>"2
set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
set/a enc4=%chr3%"&"63
::echo The shifted data: %enc1% %enc2% %enc3% %enc4%
if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
::echo The shifted data is encoded as:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
goto :encloop
:encbreak
echo The string encoded data is
goto :eof
:dec
rem And find the length of the encoded string
set/p=%encstr%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo The length of the encoded string is: %strlen% bytes
del .str
rem Find the number of offsets during encoding from the encoded string encstr
set str=
for /l %%l in (0,1,%strlen%) do (
for /l %%m in (0,1,64) do (
if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
set str=!str!/%%m
)
)
)
set a=1&set b=4
:decloop
if %strlen% equ 0 goto :decbreak
for /f "tokens=%a%-%b% delims=/" %%i in ("%str%") do set enc1=%%i&set enc2=%%j&set enc3=%%k&set enc4=%%l
::echo The offsets of the 4 bytes are respectively: %enc1% %enc2% %enc3% %enc4%
set/a a+=4&set/a b+=4
set/a strlen-=4
set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))-32
set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))-32
set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)-32
::echo The decimal after decoding the 4 bytes and subtracting 32 is: %chr1% %chr2% %chr3%
if %enc4% equ 64 if %enc3% equ 64 (set chr3=107&set chr2=107) else (set chr3=107)
::echo The decoded data is:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
set decstr=!decstr!!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
goto :decloop
:decbreak
echo The encoded data decoded is
goto :eof
|
|
2007-1-11 01:01 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
0401兄十分厉害,佩服
Brother 0401 is very powerful, admired
|
|
2007-1-11 03:05 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-1-11 07:09 |
|
|
chenall
银牌会员
    
积分 1276
发帖 469
注册 2002-12-23 来自 福建泉州
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
学习了.
试着将0401的代码修改了一下,利用DEBUG将结果得到的16进制写入到文件.
就可以得到原来的字符了.
将0401另外发了一个十进制转十六进制的批处理整进来了.
这个解码长度有限制的.我对DEBUG不熟.
debug这一段是抄 redtek 的 QQ密码转PwdHash的批处理
::code by 0401
@echo off
setlocal
setlocal enabledelayedexpansion
set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set str=
set/p "str=请输入需要编码的字符串:"
if not defined str exit/b
call :enc
call :dec
exit/b
:enc
rem 两个比较的文件名为:
rem 将字符串放到文件中等待比较(fc)并求字符串长度
set/p=%str%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo 原始字符串长度为: %strlen% 字节
set str_len=%strlen%
rem 生成fc用来与字符串比较的文件
for /l %%l in (0,1,%strlen%) do >>.cmp set/p= <nul
rem 将比较后得到的字符串的16进制存储到变量
for /f "tokens=3" %%i in ('fc/b .cmp .str^|find "A1"') do (set strhex=!strhex!%%i)
del .cmp .str
echo 转换后的16进制为: %strhex%
:encloop
if not defined strhex goto :encbreak
set chr1=0x!strhex:~0,2!
set chr2=0x!strhex:~2,2!
set chr3=0x!strhex:~4,2!
set strhex=%strhex:~6%
for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
set/a enc1=%chr1%">>"2
set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
set/a enc4=%chr3%"&"63
::echo 移位后得到的数据:%enc1% %enc2% %enc3% %enc4%
if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
::echo 移位后的数据编码为:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
goto :encloop
:encbreak
echo 字符串编码后的数据为
goto :eof
:dec
rem 并求编码字符串长度
set/p=%encstr%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo 编码后的字符串长度为: %strlen% 字节
del .str
rem 从编码的字符串encstr中求出编码时偏移的数量
set str=
for /l %%l in (0,1,%strlen%) do (
for /l %%m in (0,1,64) do (
if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
set str=!str!/%%m
)
)
)
set a=1&set b=4
:decloop
if %strlen% equ 0 goto :decbreak
for /f "tokens=%a%-%b% delims=/" %%i in ("%str%") do set enc1=%%i&set enc2=%%j&set enc3=%%k&set enc4=%%l
::echo 4个字节的偏移分别为: %enc1% %enc2% %enc3% %enc4%
set/a a+=4&set/a b+=4
set/a strlen-=4
set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))
set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))
set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)
::echo 4个字节解码后再减去32得到的十进制为: %chr1% %chr2% %chr3%
call :_d2h chr1 %chr1%
call :_d2h chr2 %chr2%
call :_d2h chr3 %chr3%
::echo 4个字节解码后再减去32得到的十进制为: %chr1% %chr2% %chr3%
::if %enc4% equ 64 if %enc3% equ 64 (set chr3=107&set chr2=107) else (set chr3=107)
::echo 解码后的数据为:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
set decstr=!decstr! %chr1% %chr2% %chr3%
goto :decloop
:decbreak
pause
set /a str_len+=1
echo exit|%ComSpec%/kprompt e 100 $_%decstr%$_rcx$_%str_len%$_n tmp.tmp$_w$_q$_|debug>nul
chcp 936>nul
set/p=编码的数据解码后为:<nul
type tmp.tmp
del tmp.tmp>nul
echo.
pause
goto :eof
:_d2h
set hex=
set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
set d=0
for %%i in (%hexstr%) do (set d!d!=%%i&set/a d+=1)
set scanf=%2
set tscanf=
call :d2h
if not defined hex set hex=0
set %1=%hex%
goto :eof
:d2h
if %scanf% equ 0 goto :eof
set/a tscanf=%scanf%"&"15
set/a scanf">>="4
set hex=!d%tscanf%!!hex!
goto :d2h
Learned.
I tried to modify the code of 0401, and used DEBUG to write the obtained hexadecimal results into a file.
Then the original characters can be obtained.
I also included another batch file for decimal to hexadecimal conversion for 0401.
There is a length limit for this decoding. I am not familiar with DEBUG.
This part of DEBUG is copied from redtek's batch file for QQ password to PwdHash.
::code by 0401
@echo off
setlocal
setlocal enabledelayedexpansion
set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set str=
set/p "str=Please enter the string to be encoded: "
if not defined str exit/b
call :enc
call :dec
exit/b
:enc
rem The two comparison file names are:
rem Put the string in the file for comparison (fc) and find the length of the string
set/p=%str%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo The original string length is: %strlen% bytes
set str_len=%strlen%
rem Generate the file for fc to compare with the string
for /l %%l in (0,1,%strlen%) do >>.cmp set/p= <nul
rem Store the hexadecimal of the compared string into a variable
for /f "tokens=3" %%i in ('fc/b .cmp .str^|find "A1"') do (set strhex=!strhex!%%i)
del .cmp .str
echo The converted hexadecimal is: %strhex%
:encloop
if not defined strhex goto :encbreak
set chr1=0x!strhex:~0,2!
set chr2=0x!strhex:~2,2!
set chr3=0x!strhex:~4,2!
set strhex=%strhex:~6%
for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
set/a enc1=%chr1%">>"2
set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
set/a enc4=%chr3%"&"63
::echo The data after shifting is: %enc1% %enc2% %enc3% %enc4%
if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
::echo The encoded data after shifting is:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
goto :encloop
:encbreak
echo The encoded data of the string is
goto :eof
:dec
rem And find the length of the encoded string
set/p=%encstr%<nul>.str
for %%f in (.str) do set strlen=%%~zf
echo The length of the encoded string is: %strlen% bytes
del .str
rem Find the number of offsets during encoding from the encoded string encstr
set str=
for /l %%l in (0,1,%strlen%) do (
for /l %%m in (0,1,64) do (
if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
set str=!str!/%%m
)
)
)
set a=1&set b=4
:decloop
if %strlen% equ 0 goto :decbreak
for /f "tokens=%a%-%b% delims=/" %%i in ("%str%") do set enc1=%%i&set enc2=%%j&set enc3=%%k&set enc4=%%l
::echo The offsets of the 4 bytes are respectively: %enc1% %enc2% %enc3% %enc4%
set/a a+=4&set/a b+=4
set/a strlen-=4
set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))
set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))
set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)
::echo The decimal obtained by decoding the 4 bytes and then subtracting 32 is: %chr1% %chr2% %chr3%
call :_d2h chr1 %chr1%
call :_d2h chr2 %chr2%
call :_d2h chr3 %chr3%
::echo The decimal obtained by decoding the 4 bytes and then subtracting 32 is: %chr1% %chr2% %chr3%
::if %enc4% equ 64 if %enc3% equ 64 (set chr3=107&set chr2=107) else (set chr3=107)
::echo The decoded data is:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
set decstr=!decstr! %chr1% %chr2% %chr3%
goto :decloop
:decbreak
pause
set /a str_len+=1
echo exit|%ComSpec%/kprompt e 100 $_%decstr%$_rcx$_%str_len%$_n tmp.tmp$_w$_q$_|debug>nul
chcp 936>nul
set/p=The decoded data of the encoded data is:<nul
type tmp.tmp
del tmp.tmp>nul
echo.
pause
goto :eof
:_d2h
set hex=
set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
set d=0
for %%i in (%hexstr%) do (set d!d!=%%i&set/a d+=1)
set scanf=%2
set tscanf=
call :d2h
if not defined hex set hex=0
set %1=%hex%
goto :eof
:d2h
if %scanf% equ 0 goto :eof
set/a tscanf=%scanf%"&"15
set/a scanf">>="4
set hex=!d%tscanf%!!hex!
goto :d2h
|

QQ:366840202
http://chenall.net |
|
2007-1-25 07:05 |
|
|
0401
中级用户
   带走
积分 435
发帖 88
注册 2005-9-24
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
呵呵,漂亮。讨论又有进展了。不过我对Debug也很陌生,看来得补补了。
Hehe, nice. The discussion has made progress again. But I'm also unfamiliar with Debug, it seems I need to catch up.
|
|
2007-1-25 09:13 |
|
|
chenall
银牌会员
    
积分 1276
发帖 469
注册 2002-12-23 来自 福建泉州
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
再贴一个比较完美一点的.
接下去将这个再修改一下就可以做成一个
将指定文件用BASE64编码/解码的工具
代码应该还可以再精简一下.
- ::code by 0401
- ::chenall 修改于 2007.01.25
- @echo off
- setlocal
- setlocal enabledelayedexpansion
- set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
- set str=
- set/p "str=请输入需要编码的字符串:"
- if not defined str exit/b
- call :enc
- call :dec
- exit/b
- :enc
- rem 两个比较的文件名为:
- rem 将字符串放到文件中等待比较(fc)并求字符串长度
- set/p=%str%<nul>.str
- for %%f in (.str) do set strlen=%%~zf
- echo 原始字符串长度为: %strlen% 字节
- set str_len=%strlen%
- rem 生成fc用来与字符串比较的文件
- del _*.cmp 2>nul
- for /l %%l in (1,1,%strlen%) do (
- >>_a.cmp set/p=a<nul
- >>_b.cmp set/p=b<nul
- )
- fc/b _a.cmp .str|find ":">tmp.str
- fc/b _b.cmp .str|find ":">>tmp.str
- sort tmp.str>_a.cmp
- rem 将比较后得到的字符串的16进制存储到变量
- for /f "tokens=1,3" %%i in (_a.cmp) do (
- if not "!n!"=="%%i" set strhex=!strhex!%%j
- set n=%%i
- )
- ::for /f "tokens=3" %%i in ('fc/b .cmp .str^|find ":"') do (set strhex=!strhex!%%i)
- del *.cmp *.str 2>nul
- echo 转换后的16进制为: %strhex%
- :encloop
- if not defined strhex goto :encbreak
- set chr1=0x!strhex:~0,2!
- set chr2=0x!strhex:~2,2!
- set chr3=0x!strhex:~4,2!
- set strhex=%strhex:~6%
- for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
- set/a enc1=%chr1%">>"2
- set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
- set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
- set/a enc4=%chr3%"&"63
- ::echo 移位后得到的数据:%enc1% %enc2% %enc3% %enc4%
- if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
- ::echo 移位后的数据编码为:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
- set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
- ::for %%i in (enc1 enc2 enc3 enc4) do (
- :: if !%%i! lss 10 (set/p=0!%%i!<nul>>tmp.bb) else (set/p=!%%i!<nul>>tmp.bb)
- ::)
- goto :encloop
- :encbreak
- echo 字符串%str%]编码后的数据为%encstr%]
- ::echo 字符串编码后的数据为 >>tmp.aa
- goto :eof
- :dec
- rem 并求编码字符串长度
- set/p=%encstr%<nul>.str
- for %%f in (.str) do set strlen=%%~zf
- echo 编码后的字符串长度为: %strlen% 字节
- del .str
- rem 从编码的字符串encstr中求出编码时偏移的数量
- set str=
- for /l %%l in (0,1,%strlen%) do (
- for /l %%m in (0,1,64) do (
- if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
- if %%m lss 10 (
- set str=!str!0%%m
- ) else (
- set str=!str!%%m
- )
- )
- )
- )
- set a=1&set b=4&set e=0
- del debug.src 2>nul
- :decloop
- if not defined str goto :decbreak
- set /a enc1=1!str:~0,2!-100
- set /a enc2=1!str:~2,2!-100
- set /a enc3=1!str:~4,2!-100
- set /a enc4=1!str:~6,2!-100
- set str=%str:~8%
- for %%i in (enc1 enc2 enc3 enc3 enc4) do (
- if !%%i! leq 0 set %%i=0
- if !%%i! equ 64 set %%i=0
- )
- ::echo 4个字节的偏移分别为: %enc1% %enc2% %enc3% %enc4%
- set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))
- set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))
- set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)
- ::echo 4个字节解码后再减去32得到的十进制为: %chr1% %chr2% %chr3%
- call :_d2h chr1 %chr1%
- call :_d2h chr2 %chr2%
- call :_d2h chr3 %chr3%
- ::echo 4个字节解码后再减去32得到的十六进制为: %chr1% %chr2% %chr3%
- ::echo 解码后的数据为:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
- set /a ee=0x100+3*e
- call :_d2h ee %ee%
- >>debug.src echo e %ee% %chr1% %chr2% %chr3%
- ::set/p=%chr1%%chr2%%chr3%<NUL >>BB.TXT
- set /a e+=1
- goto :decloop
- :decbreak
- pause
- set /a str_len+=1
- >>debug.src echo rcx
- >>debug.src echo %str_len%
- >>debug.src echo n tmp.tmp
- >>debug.src echo w
- >>debug.src echo q
- debug<debug.src
- del debug.src
- chcp 936>nul
- echo 编码的数据%encstr%]
- echo.
- set/p=解码后为:<nul
- type tmp.tmp
- del tmp.tmp>nul
- echo.
- pause
- goto :eof
- :_d2h
- set hex=
- set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
- set d=0
- for %%i in (%hexstr%) do (set d!d!=%%i&set/a d+=1)
- set scanf=%2
- set tscanf=
- call :d2h
- if not defined hex set hex=0
- set %1=%hex%
- goto :eof
- :d2h
- if %scanf% equ 0 goto :eof
- set/a tscanf=%scanf%"&"15
- set/a scanf">>="4
- set hex=!d%tscanf%!!hex!
- goto :d2h
chenall 发表于: 2007-01-25 15:35
Last edited by chenall on 2007-1-26 at 04:37 AM ]
Post another relatively perfect one.
Next, modify this a bit more and it can be made into a tool for encoding/decoding specified files with BASE64.
The code can probably be further streamlined.
- ::code by 0401
- ::chenall modified on 2007.01.25
- @echo off
- setlocal
- setlocal enabledelayedexpansion
- set B64CODE=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
- set str=
- set/p "str=Please enter the string to be encoded: "
- if not defined str exit/b
- call :enc
- call :dec
- exit/b
- :enc
- rem The two file names for comparison are:
- rem Put the string in a file for comparison (fc) and find the length of the string
- set/p=%str%<nul>.str
- for %%f in (.str) do set strlen=%%~zf
- echo The length of the original string is: %strlen% bytes
- set str_len=%strlen%
- rem Generate the file for fc to compare with the string
- del _*.cmp 2>nul
- for /l %%l in (1,1,%strlen%) do (
- >>_a.cmp set/p=a<nul
- >>_b.cmp set/p=b<nul
- )
- fc/b _a.cmp .str|find ":">tmp.str
- fc/b _b.cmp .str|find ":">>tmp.str
- sort tmp.str>_a.cmp
- rem Store the 16 - bit hexadecimal of the compared string into a variable
- for /f "tokens=1,3" %%i in (_a.cmp) do (
- if not "!n!"=="%%i" set strhex=!strhex!%%j
- set n=%%i
- )
- ::for /f "tokens=3" %%i in ('fc/b .cmp .str^|find ":"') do (set strhex=!strhex!%%i)
- del *.cmp *.str 2>nul
- echo The converted hexadecimal is: %strhex%
- :encloop
- if not defined strhex goto :encbreak
- set chr1=0x!strhex:~0,2!
- set chr2=0x!strhex:~2,2!
- set chr3=0x!strhex:~4,2!
- set strhex=%strhex:~6%
- for %%i in (chr1 chr2 chr3) do if "!%%i!"=="0x" set %%i=0
- set/a enc1=%chr1%">>"2
- set/a enc2=((%chr1%"&"3)"<<"4)"|"(%chr2%">>"4)
- set/a enc3=((%chr2%"&"15)"<<"2)"|"(%chr3%">>"6)
- set/a enc4=%chr3%"&"63
- ::echo The data after shifting is: %enc1% %enc2% %enc3% %enc4%
- if %chr3% equ 0 if %chr2% equ 0 (set enc4=64& set enc3=64) else (set enc4=64)
- ::echo The encoded data after shifting is:!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
- set encstr=!encstr!!B64CODE:~%enc1%,1!!B64CODE:~%enc2%,1!!B64CODE:~%enc3%,1!!B64CODE:~%enc4%,1!
- ::for %%i in (enc1 enc2 enc3 enc4) do (
- :: if !%%i! lss 10 (set/p=0!%%i!<nul>>tmp.bb) else (set/p=!%%i!<nul>>tmp.bb)
- ::)
- goto :encloop
- :encbreak
- echo The encoded data of the string %str%] is %encstr%]
- ::echo 字符串编码后的数据为 >>tmp.aa
- goto :eof
- :dec
- rem And find the length of the encoded string
- set/p=%encstr%<nul>.str
- for %%f in (.str) do set strlen=%%~zf
- echo The length of the encoded string is: %strlen% bytes
- del .str
- rem Find the number of offsets during encoding from the encoded string encstr
- set str=
- for /l %%l in (0,1,%strlen%) do (
- for /l %%m in (0,1,64) do (
- if "!encstr:~%%l,1!"=="!B64CODE:~%%m,1!" (
- if %%m lss 10 (
- set str=!str!0%%m
- ) else (
- set str=!str!%%m
- )
- )
- )
- )
- set a=1&set b=4&set e=0
- del debug.src 2>nul
- :decloop
- if not defined str goto :decbreak
- set /a enc1=1!str:~0,2!-100
- set /a enc2=1!str:~2,2!-100
- set /a enc3=1!str:~4,2!-100
- set /a enc4=1!str:~6,2!-100
- set str=%str:~8%
- for %%i in (enc1 enc2 enc3 enc3 enc4) do (
- if !%%i! leq 0 set %%i=0
- if !%%i! equ 64 set %%i=0
- )
- ::echo The offsets of the 4 bytes are respectively: %enc1% %enc2% %enc3% %enc4%
- set/a chr1=((%enc1%"<<"2)"|"(%enc2%">>"4))
- set/a chr2=(((%enc2%"&"15)"<<"4)"|"(%enc3%">>"2))
- set/a chr3=(((%enc3%"&"3)"<<"6)"|"%enc4%)
- ::echo The decimal obtained by subtracting 32 from the 4 bytes after decoding is: %chr1% %chr2% %chr3%
- call :_d2h chr1 %chr1%
- call :_d2h chr2 %chr2%
- call :_d2h chr3 %chr3%
- ::echo The hexadecimal obtained by subtracting 32 from the 4 bytes after decoding is: %chr1% %chr2% %chr3%
- ::echo The decoded data is:!ASCII:~%chr1%,1!!ASCII:~%chr2%,1!!ASCII:~%chr3%,1!
- set /a ee=0x100+3*e
- call :_d2h ee %ee%
- >>debug.src echo e %ee% %chr1% %chr2% %chr3%
- ::set/p=%chr1%%chr2%%chr3%<NUL >>BB.TXT
- set /a e+=1
- goto :decloop
- :decbreak
- pause
- set /a str_len+=1
- >>debug.src echo rcx
- >>debug.src echo %str_len%
- >>debug.src echo n tmp.tmp
- >>debug.src echo w
- >>debug.src echo q
- debug<debug.src
- del debug.src
- chcp 936>nul
- echo The encoded data %encstr%]
- echo.
- set/p=Decoded as:<nul
- type tmp.tmp
- del tmp.tmp>nul
- echo.
- pause
- goto :eof
- :_d2h
- set hex=
- set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
- set d=0
- for %%i in (%hexstr%) do (set d!d!=%%i&set/a d+=1)
- set scanf=%2
- set tscanf=
- call :d2h
- if not defined hex set hex=0
- set %1=%hex%
- goto :eof
- :d2h
- if %scanf% equ 0 goto :eof
- set/a tscanf=%scanf%"&"15
- set/a scanf">>="4
- set hex=!d%tscanf%!!hex!
- goto :d2h
chenall posted on: 2007-01-25 15:35
Last edited by chenall on 2007-1-26 at 04:37 AM ]
|

QQ:366840202
http://chenall.net |
|
2007-1-25 23:56 |
|
|
0401
中级用户
   带走
积分 435
发帖 88
注册 2005-9-24
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
to chenall兄:
确实已经可以写个BASE64编码/解码的工具了,我也有此打算了,不过不知道时间允不允许。呵呵
顺便提一下,兄为了用fc比较文件,使用fsutil file createnew命令创建一个等大的文件,但这样fsutil只能是管理员组的成员才能使用,适用性打了点折扣。何不试试5楼的方法,或者用debug的f子命令来填充一个二进制全为0的等大文件。
-------------------------------------------------
补充的:如果用f子命令来填充也得填充2个不同内容的文件,因为如果处理的是一个文件,就不保证不碰到二进制为0的字节。
Last edited by 0401 on 2007-1-28 at 01:09 PM ]
To brother chenall:
Indeed, a BASE64 encoding/decoding tool can already be written. I also have this plan, but I don't know if there will be time available. Hehe.
By the way, brother, in order to use fc to compare files, you used the fsutil file createnew command to create an equally sized file. But in this way, fsutil can only be used by members of the administrator group, which reduces the applicability to some extent. Why not try the method in floor 5, or use the f sub-command of debug to fill an equally sized file with all binary 0s.
-------------------------------------------------
Supplementary: If you use the f sub-command to fill, you also need to fill two files with different contents, because if you are dealing with a single file, it is not guaranteed that you will not encounter bytes with binary 0.
Last edited by 0401 on 2007-1-28 at 01:09 PM ]
|
|
2007-1-26 03:03 |
|
|
chenall
银牌会员
    
积分 1276
发帖 469
注册 2002-12-23 来自 福建泉州
状态 离线
|
|
2007-1-26 04:38 |
|
|