You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.1 KiB

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "aes.h"
//#define PaddingMode_None
#define PaddingMode_Zeros
//#define PaddingMode_PKCS5or7
#define MAXLEN 1024
void printASCCI(char *str, int len) {
int c,i;
for(i = 0; i < len; i++) {
c = (int)*str++;
c = c & 0x000000ff;
printf("0x%x ", c);
}
printf("\n");
}
int main(int argc, char const *argv[])
{
char key[17] = "abcdefghigklmnop";
int klen;
char p[MAXLEN]="ABCDEFGHIGKLMN0";
int plen = strlen(p);
printf("AES...ing..................\n");
if(plen == 0)
{
printf("plen erro?\n");
return ;
}
#ifdef PaddingMode_Zeros
if(plen % 16 != 0)
plen=(16 - plen%16) + plen;
else
plen+=16;
#endif
#ifdef PaddingMode_PKCS5or7
if(plen % 16 != 0)
{
int len_num = 16 - plen%16;
int i = 0;
for(i;i<len_num;i++)
p[plen+i] = len_num;
plen+=len_num;
}
else
{
int i = 0;
for(i;i<16;i++)
p[plen+i] = 16;
plen+=16;
}
#endif
aes(p, plen, key);//AES¼ÓÃÜ
printf("After Aes ASCCI is:\n");
printASCCI(p, plen);
deAes(p, plen, key);//AES½âÃÜ
printf("After DAes ASCCI is:\n");
printASCCI(p, plen);
return 0;
}