字节高低4位交换
本帖最后由 jixun66 于 2018-3-2 12:10 编辑对每个字节的高低4位进行交换。
起因:[歌者盟视频加密](https://www.52pojie.cn/thread-704045-1-1.html)
用法:解压,拖放文件到程序上,或自行查阅说明。
```
#include <fstream>
#include <string>
#include <algorithm>
#define BUFFER_SIZE (4 * 1024)
unsigned char g_buffer;
void TransformBuffer(unsigned char* buffer, const int size)
{
for(int i = 0; i < size; i++)
{
const unsigned char c = buffer;
buffer = (c >> 4) | (c << 4);
}
}
void ProcessFile(std::wstring path)
{
printf("Processing %ls...\n", path.c_str());
std::fstream in_stream;
std::fstream out_stream;
in_stream.open(path, std::fstream::in | std::fstream::binary);
in_stream.seekg(0, in_stream.end);
int length = static_cast<int>(in_stream.tellg());
in_stream.seekg(0, in_stream.beg);
const std::string::size_type ext_pos = path.find_last_of(L'.');
std::wstring output_path;
if (ext_pos == std::string::npos)
{
output_path = path + L".swap";
} else
{
output_path = path.substr(0, ext_pos) + L".swap" + path.substr(ext_pos);
}
out_stream.open(output_path, std::fstream::out | std::fstream::binary);
char* signed_buffer_ptr = reinterpret_cast<char*>(g_buffer);
while(length > 0)
{
const int transform_size = std::min(BUFFER_SIZE, length);
in_stream.read(signed_buffer_ptr, transform_size);
TransformBuffer(g_buffer, transform_size);
out_stream.write(signed_buffer_ptr, transform_size);
length -= transform_size;
}
}
int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
printf("4 bit swapper by jixun66@52pojie\n");
if (argc == 1)
{
printf("Usage: <swap4bit> <file1> ...]\n\n");
} else for(int i = 1; i < argc; i++)
{
ProcessFile(argv);
}
return 0;
}
``` 大佬,? 远方通用算法注册机 v2 在 远方驾考 V2018.05.20 版本下失效了。 学习下,写的还不错 向提供源代码者表示感谢
页:
[1]