FEALib.h
/*
BytesEncrypt字节流加密函数
buffer输入为明文,输出为密文。明文密文共用。
len为明文长度。
mainkey为系统主密钥或用户自定义主密钥。
bits为主密钥位数32-2048位。
subkey为32位子密钥输入。
函数返回32位子密钥,级联时需要。
*/
unsigned long BytesEncrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned long subkey);
/*
BytesDecrypt字节流解密函数
buffer输入为密文,输出为明文。明文密文共用。
len为密文长度。
mainkey为系统主密钥或用户自定义主密钥。
bits为主密钥位数32-2048位。
subkey为32位子密钥输入。
函数返回32位子密钥,级联时需要。
*/
unsigned long BytesDecrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned long subkey);
[url=]复制[/url]
mian.c
#include <REG52.H>
#include <stdio.h>
#include "FEA32Lib.h"
#ifdef MONITOR51
char code reserve [3] _at_ 0x23;
#endif
/*-----------------------------------------------------------------------------------------------
HotFEA加解密程序_FEA32_ROM HotPower@163.com 2023-10-13 4:57:11于北京
-----------------------------------------------------------------------------------------------*/
code unsigned char FEAMainKeyArray[32] = {//系统默认FEA32的32位主密钥,自定义32*8=256位主密钥
0x7D, 0x35, 0x82, 0x36, 0xA6, 0x05, 0x0F, 0xB8, 0x2B, 0x52, 0x50, 0x5D, 0x5B, 0x63, 0x3F, 0x8D,
0x8D, 0xA0, 0x2D, 0xF2, 0x7F, 0x52, 0xDF, 0x90, 0x1D, 0x30, 0xBD, 0x62, 0xEF, 0xC2, 0x62, 0xEF
};
unsigned long FEASubKeyEncrypt = 0xB7073293;//系统默认FEA的32位加密子密钥,可以自定义32位加密子密钥
unsigned long FEASubKeyDecrypt = 0xB7073293;//系统默认FEA的32位解密子密钥,可以自定义32位解密子密钥
xdata unsigned char FEATextBuffers[10] = {//明文数组10个字节 ,外部存储器
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};
void main (void) {
int i;
#ifndef MONITOR51
SCON = 0x50;
TMOD |= 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
#endif
for(i = 0;i < 10;i++){
if(i == 0) printf ("原始明文流: %02X", (int)FEATextBuffers);
else printf (", %02X", (int)FEATextBuffers);
}
printf ("\n");
BytesEncrypt(&FEATextBuffers, 10, &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(&FEATextBuffers, 10, &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(FEATextBuffers, 10, FEAMainKeyArray, 256, FEASubKeyEncrypt);//自定义256位主密钥,级联
FEASubKeyDecrypt = BytesDecrypt(FEATextBuffers, 10, FEAMainKeyArray, 256, FEASubKeyDecrypt);//自定义256位主密钥,级联
}
while (1) {
printf ("End\n"); /* Print "Hello World" */
}
}
|