0x0 TEA加密
在vs2013下成功编译并运行
TEA 正如名字那样,是个Tiny的算法,加密速度和效率都很高。
一般迭代32次,密钥为16字节(128bit)
明文是以每sizeof(unsigned int) * 2 分块来加密的
#include <cstdio>
#include <Windows.h>
#include <cstring>
void TEA_Encrypt(unsigned char *key, unsigned char *data)
{
DWORD encryptCount = 0;
DWORD keyPart[4];
DWORD left;
DWORD right;
DWORD delta = 0x9e3779b9;
DWORD sum = 0;
unsigned int i, j;
if ((strlen((const char *)data) % (sizeof(unsigned int) * 2)) != 0) {
printf("Error in alignment!\n");
return;
}
encryptCount = strlen((const char *)data) / (sizeof(unsigned int) * 2);//获取加密块的次数
for (i = 0, j = 0; i < 4; i++, j += 4) {
keyPart[i] = (key[j] << 24) | (key[j + 1] << 16) | (key[j + 2] << 8) | (key[j + 3]);//将密钥使其转换成4个DWORD型数据
}
for (i = 0, j = 0; i < encryptCount