FEA32Lib.h
/*
BytesEncrypt字节流加密函数
buffer输入为明文,输出为密文。明文密文共用。
len为明文长度。
mainkey为系统主密钥或用户自定义主密钥。
bits为主密钥位数32-2048位。
subkey为32位子密钥输入。
函数返回32位子密钥,级联时需要。
*/
unsigned int BytesEncrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned int subkey);
/*
BytesDecrypt字节流解密函数
buffer输入为密文,输出为明文。明文密文共用。
len为密文长度。
mainkey为系统主密钥或用户自定义主密钥。
bits为主密钥位数32-2048位。
subkey为32位子密钥输入。
函数返回32位子密钥,级联时需要。
*/
unsigned int BytesDecrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned int subkey);
[url=]复制[/url]
FEA32.CPP
// FEA32.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include<stdlib.h>
#include "FEA32Lib.h"
#pragma comment(lib,"FEA32Lib.lib")
/*-----------------------------------------------------------------------------------------------
HotFEA加解密程序_FEA32 HotPower@163.com 2023-10-14 21:30:00于西安雁塔菜地
----------------------------------------------------------------------------------------------*/
const unsigned char FEAMainKeyArray[16] = {//系统默认FEA32的32位主密钥,自定义128位主密钥(可以自定义32-2048位主密钥)
0x7D, 0x35, 0x82, 0x36, 0xA6, 0x05, 0x0F, 0xB8, 0x2B, 0x52, 0x50, 0x5D, 0x5B, 0x63, 0x3F, 0x8D
};
unsigned int FEASubKeyEncrypt = 0xB7073293;//系统默认FEA的32位加密子密钥,可以自定义32位加密子密钥
unsigned int FEASubKeyDecrypt = 0xB7073293;//系统默认FEA的32位解密子密钥,可以自定义32位解密子密钥
unsigned char FEATextBuffers[1024] = {//明文数组1024个字节 ,外部存储器
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};
int main(int argc, char* argv[])
{
int i;
for (i = 0; i < 10; i++) {
if (i == 0) printf("原始明文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
BytesEncrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyEncrypt);//系统32位主密钥,自定义256位主密钥,不级联
for (i = 0; i < 10; i++) {
if (i == 0) printf("加密密文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
BytesDecrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyDecrypt);//系统32位主密钥,自定义256位主密钥,不级联
for (i = 0; i < 10; i++) {
if (i == 0) printf("解密明文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
for (i = 0; i < 25; i++) {
FEASubKeyEncrypt = BytesEncrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyEncrypt);//自定义256位主密钥,级联
FEASubKeyDecrypt = BytesDecrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyDecrypt);//自定义256位主密钥,级联
}
system("pause");
return 0;
}
FEA32Lib.CPP
// FEA32.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include<stdlib.h>
#include "FEA32Lib.h"
#pragma comment(lib,"FEA32Lib.lib")
/*-----------------------------------------------------------------------------------------------
HotFEA加解密程序_FEA32 HotPower@163.com 2023-10-14 21:30:00于西安雁塔菜地
----------------------------------------------------------------------------------------------*/
const unsigned char FEAMainKeyArray[16] = {//系统默认FEA32的32位主密钥,自定义128位主密钥(可以自定义32-2048位主密钥)
0x7D, 0x35, 0x82, 0x36, 0xA6, 0x05, 0x0F, 0xB8, 0x2B, 0x52, 0x50, 0x5D, 0x5B, 0x63, 0x3F, 0x8D
};
unsigned int FEASubKeyEncrypt = 0xB7073293;//系统默认FEA的32位加密子密钥,可以自定义32位加密子密钥
unsigned int FEASubKeyDecrypt = 0xB7073293;//系统默认FEA的32位解密子密钥,可以自定义32位解密子密钥
unsigned char FEATextBuffers[1024] = {//明文数组1024个字节 ,外部存储器
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};
int main(int argc, char* argv[])
{
int i;
for (i = 0; i < 10; i++) {
if (i == 0) printf("原始明文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
BytesEncrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyEncrypt);//系统32位主密钥,自定义256位主密钥,不级联
for (i = 0; i < 10; i++) {
if (i == 0) printf("加密密文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
BytesDecrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyDecrypt);//系统32位主密钥,自定义256位主密钥,不级联
for (i = 0; i < 10; i++) {
if (i == 0) printf("解密明文流: %02X", (int)FEATextBuffers);
else printf(", %02X", (int)FEATextBuffers);
}
printf("\n");
for (i = 0; i < 25; i++) {
FEASubKeyEncrypt = BytesEncrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyEncrypt);//自定义256位主密钥,级联
FEASubKeyDecrypt = BytesDecrypt((unsigned char*)FEATextBuffers, 10, (unsigned char*)FEAMainKeyArray, 256, FEASubKeyDecrypt);//自定义256位主密钥,级联
}
system("pause");
return 0;
}
|