1.1 版
修复了操作数错误的问题。
将- For /L %%_ in (0,1,3) Do (
- Set /A "bytPassword[%%_]=lngTemp%%256"
- Set /A "lngTemp=(lngTemp-lngTemp%%256)/256"
- )
复制代码 改为- For /L %%_ in (0,1,3) Do (
- Set /A "bytPassword[%%_]=lngTemp&0x000000FF"
- Set /A "lngTemp=(lngTemp>>8)&0x00FFFFFF"
- )
复制代码 源码:- @Echo Off
- If "%~3" == "" (
- @Call :Usage
- @Exit /B 1
- )
- @Goto :Main
-
- :Main
-
- If Not Exist "%~1" (
- Echo.错误:无法访问明文文件
- @Exit /B 2
- )
-
- SetLocal EnableExtensions DisableDelayedExpansion
-
- For /F "Delims= Skip=1" %%_ in ('Certutil -hashFile "%~1" SHA256') Do (
- If Not Defined strHashInFile Set strHashInFile=%%_
- )
-
- For /F "Delims=" %%_ in ('Dir /B %~1') Do (
- Set lngFileSize=%%~z_
- )
-
- Certutil -EnCodeHex -F "%~1" %strHashInFile%.tmp
-
- SetLocal EnableExtensions EnableDelayedExpansion
-
- For /F "Tokens=1,2 Delims= " %%_ in ('Type "%strHashInFile%.tmp"') Do (
- Set /A lngTemp=0x%%_
- Set Line[!lngTemp!]=%%`
- )
-
- Set /A "lngTemp=lngFileSize"
-
- For /L %%_ in (0,16,%lngTemp%) Do (
- Set Line[%%_]=!Line[%%_]:~0,48!
- )
-
- Set lngIndex=0
-
- For /L %%_ in (0,16,%lngTemp%) Do (
- For %%# in (!Line[%%_]!) Do (
- If "%%#" Neq "" (
- Set /A bytData[!lngIndex!]=0x%%#
- Set /A lngIndex+=1
- )
- )
- )
-
- Set /A "lngTemp=%~3"
-
- For /L %%_ in (0,1,3) Do (
- Set /A "bytPassword[%%_]=lngTemp&0x000000FF"
- Set /A "lngTemp=(lngTemp>>8)&0x00FFFFFF"
- )
-
- For %%_ in (0 1 2 3 4 5 6 7 8 9 A B C D E F) Do (
- For %%` in (0 1 2 3 4 5 6 7 8 9 A B C D E F) Do (
- Set /A lngTemp=0x%%_%%`
- Set bytHexTab[!lngTemp!]=%%_%%`
- )
- )
-
- Set /A "lngTemp=lngIndex-1"
-
- For /L %%_ in (0,1,%lngTemp%) Do (
- Set /A "bytTemp=(%%_)%%4"
- Set /A "bytData[%%_]=bytData[%%_]^^bytPassword[!bytTemp!]"
- )
-
- Cd. > %strHashInFile%.tm$
-
- For /L %%_ in (0,1,%lngTemp%) Do (
- For %%` in (!bytData[%%_]!) Do (
- Set /P strTemp=!bytHexTab[%%`]! < Nul >> %strHashInFile%.tm$
- )
- )
-
- Certutil -DeCodeHex -F %strHashInFile%.tm$ "%~2"
-
-
- If Exist %strHashInFile%.tmp Del %strHashInFile%.tmp
- If Exist %strHashInFile%.tm$ Del %strHashInFile%.tm$
-
- EndLocal
-
- EndLocal
-
- @Exit /B 0
-
- :Usage
- Echo.Encode InFile OutFile PasFile
- Echo.
- Echo. InFile 明文文件
- Echo. OutFile 密文文件
- Echo. Pasword 密码(范围:-2,147,483,648 到 2,147,483,647)(若为 0 则等同于不加密)
- @Goto :Eof
复制代码
|