⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.cpp

📁 tea加密解密DLL,可调用相应的原文,密钥实现加密,然后通过密文,密钥解密
💻 CPP
字号:
#include "util.h"
#include <vector>

using namespace std;

char intToHexChar(int x) {
	static const char HEX[16] = {
		'0', '1', '2', '3',
		'4', '5', '6', '7',
		'8', '9', 'A', 'B',
		'C', 'D', 'E', 'F'
	};
	return HEX[x];
}

int hexCharToInt(char hex) {
	hex = toupper(hex);
	if (isdigit(hex))
		return (hex - '0');
	if (isalpha(hex))
		return (hex - 'A' + 10);
	return 0;
}

string bytesToHexString(const byte *in, size_t size) {
	string str;
	for (size_t i = 0; i < size; ++i) {
		int t = in[i];
		int a = t / 16;
		int b = t % 16;
		str.append(1, intToHexChar(a));
		str.append(1, intToHexChar(b));
		if (i != size - 1)
			str.append(1, ' ');
	}
	return str;
}

size_t hexStringToBytes(const string &str, byte *out) {

	vector<string> vec;
	string::size_type currPos = 0, prevPos = 0;
	while ((currPos = str.find(' ', prevPos)) != string::npos) {
		string b(str.substr(prevPos, currPos - prevPos));
		vec.push_back(b);
		prevPos = currPos + 1;
	}
	if (prevPos < str.size()) {
		string b(str.substr(prevPos));
		vec.push_back(b);
	}
	typedef vector<string>::size_type sz_type;
	sz_type size = vec.size();
	for (sz_type i = 0; i < size; ++i) {
		int a = hexCharToInt(vec[i][0]);
		int b = hexCharToInt(vec[i][1]);
		out[i] = a * 16 + b;
	}
	return size;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -