📄 encryp.c
字号:
#include "aes.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
DWORD Here(DWORD x)
{
unsigned int mask=~0U;
return (* (((DWORD *)&x)-1)) & mask;
}
extern DWORD TwofishCodeSize(void);
#define keySize 128
int encryption(BYTE *plainText, int block_number, BYTE *cipherText, DWORD *Key)
{ /* return 0 iff test passes */
keyInstance ki; /* key information, including tables */
cipherInstance ci; /* keeps mode (ECB, CBC) and IV */
int i,byteCnt;
if (makeKey(&ki,DIR_ENCRYPT,keySize,NULL) != TRUE)
return -1; /* 'dummy' setup for a 128-bit key */
if (cipherInit(&ci,MODE_ECB,NULL) != TRUE)
return -1; /* 'dummy' setup for cipher */
for (i=0;i<keySize/32;i++) /* select key bits */
ki.key32[i]=Key[i];
reKey(&ki); /* run the key schedule */
byteCnt = (BLOCK_SIZE/8) * block_number;
/* encrypt the bytes */
if (blockEncrypt(&ci,&ki, plainText,byteCnt*8,cipherText) != byteCnt*8)
return -1;
return 0;
}
int decryption(BYTE *cipherText, int block_number, BYTE *plainText, DWORD *Key)
{ /* return 0 iff test passes */
keyInstance ki; /* key information, including tables */
cipherInstance ci; /* keeps mode (ECB, CBC) and IV */
int i,byteCnt;
if (makeKey(&ki,DIR_DECRYPT,keySize,NULL) != TRUE)
return -1; /* 'dummy' setup for a 128-bit key */
if (cipherInit(&ci,MODE_ECB,NULL) != TRUE)
return -1; /* 'dummy' setup for cipher */
for (i=0;i<keySize/32;i++) /* select key bits */
ki.key32[i]=Key[i];
reKey(&ki); /* run the key schedule */
byteCnt = (BLOCK_SIZE/8) * block_number;
/* encrypt the bytes */
if (blockDecrypt(&ci,&ki,cipherText,byteCnt*8, plainText) != byteCnt*8)
return -1;
return 0;
}
/*
void main(void)
{
int block_number = 12;
BYTE plain[12 * BLOCK_SIZE/8];
BYTE cipher[12 * BLOCK_SIZE/8];
BYTE result[12 * BLOCK_SIZE/8];
DWORD key[keySize/32] = {3456, 4567, 5678, 6789};
int ret;
memset(plain, 0, 12 * BLOCK_SIZE/8);
strcpy(plain, "abcdefghijklmnopqrstuvwxyz");
ret = encryption(plain, 12, cipher, key);
if (ret != 0)
{
printf("error in encryption\n");
}
printf("%s\n", cipher);
ret = decryption(cipher, 12, result, key);
if (ret != 0)
{
printf("error in decryption\n");
}
if(memcmp(plain, result, 12 * BLOCK_SIZE/8))
{
printf("error\n");
}
printf("%s:Ok\n", result);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -