昨晚有人发了个VB的文本加密程序
使用了逐字节加1的恺撒密码
很快我们的版主老兄就出了VBS版
想起这种简单的文本处理还是汇编更轻巧些
只是昨天又热又困编代码还是算了
今天一场中雨凉快了许多
虽然紧张忙碌
但还是抽空写了一下
省得过了明天天一热又忘在脑后
-------------------------------------------------------
起初打算完全实现+1/-1的密码
后来考虑到为我等懒人谋福
觉得还是异或更简单实用些
+1实在太好猜了,我当初就破过某个bat2exe程序+1后的加密代码
异或算法相对比较难猜一些
而且加密/解密可以重用一个模块
本来想支持多位密码的
这样才具有实用性
可惜无论+1或者+X还是异或X都可能会得到FF
而FF无法输出到标准输出的
为了代码简单起见
还是使用了与 E0~EF 异或的方案
这样只有10~1F 的字节才可能得到FF
而这区都是控制字符
文本文件中绝难用到
------------------------------------------------------
时间原因
没有特殊情况
不准备更新它了
有兴趣的可以自己研究研究
@echo off & setlocal & chcp 437>nul & graftabl 936>nul
if "%~1"=="" (
echo.
echo.=文本文件加解密程序 :: qzwqzw :: 2007-06-05 :: Release 7
echo.
echo.=原理:使用DEBUG 脚本动态生成可执行程序对输入文件逐字节异或编码
echo.
echo.=特性:加解密互逆,多文件操作,单数字密钥
echo.
set /p file=-请输入文件名(支持通配符,默认为 .\*.txt):
set /p pass=-请输入密钥(一位0~F的十六进制数,默认为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%" && goto end
:: 生成并执行 DEBUG 脚本,生成转换程序
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 !密钥错误: "%pass%" && goto :end
:: 搜索指定路径所有匹配文件进行转换
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 !已存在文件: "%fOut%" && pause && goto :eof
echo +正在转换 "%fIn%" ...
if exist _codec.com _codec.com < "%fIn%" > "%fOut%"
if not exist "%fOut%" echo !转换失败,未生成 "%fOut%" && pause
Last edited by qzwqzw on 2007-6-5 at 12:09 PM ]
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 ]