⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aes.c

📁 该文件属于c++运行环境下AES加密程序源码。
💻 C
字号:
/* aes.c */
/*
 * Copyright (C) 2005
 * Akira Iwata & Masayuki Sato
 * Akira Iwata Laboratory,
 * Nagoya Institute of Technology in Japan.
 *
 * All rights reserved.
 *
 * This software is written by Masayuki Sato.
 * And if you want to contact us, send an email to Kimitake Wakayama
 * (wakayama@elcom.nitech.ac.jp)
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. All advertising materials mentioning features or use of this software must
 *    display the following acknowledgment:
 *    "This product includes software developed by Akira Iwata Laboratory,
 *    Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Akira Iwata Laboratory,
 *     Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
 *
 *   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
 *   AKIRA IWATA LABORATORY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 *   SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
 *   IN NO EVENT SHALL AKIRA IWATA LABORATORY BE LIABLE FOR ANY SPECIAL,
 *   INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 *   FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 *   NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION
 *   WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "aes.h"

/* **********plain statement input ********* */
int  TestData(int statemt[32],int type){
    int i=0;int ret;int ini[32]={3,4,2,6,3,7,6,4,2,5,1,2,3,2,5,4,2,1,4,3,5,2,8,3,1,3,5,3,7,4,3,6};
    switch (type){
    case 128128:case 192128:case 256128:
    srand(time(NULL));
    printf("message                \t");
    while (i < 16) {
	statemt[i]=( ret=(rand()) << 2) % 256;
	srand(ret >> ini[i]);
	++i;
    }i=0;
    while (i < 16) {
	if (statemt[i] < 16) printf("0");
	printf("%x",statemt[i]);
	++i; }
    printf("\n");break;
    case 128192:case 192192:case 256192:
	i=0;
    srand(time(NULL));
    printf("message                \t");
    while (i < 24) {
	statemt[i]=( ret=(rand() << 2)) % 256;
	srand(ret >> ini[i]);
	++i;
    }i=0;
    while (i < 24) {
	if (statemt[i] < 16) printf("0");
	printf("%x",statemt[i]);
	++i;
    }
    printf("\n"); break;
    case 128256:case 192256:case 256256:
        i=0;
    srand(time(NULL));
    printf("message                \t");
    while (i < 32) {
	statemt[i]=( ret=(rand() << 2)) % 256;
	srand(ret >> ini[i]);
	++i;
    }i=0;
    while (i < 32) {
	if (statemt[i] < 16) printf("0");
	printf("%x",statemt[i]);
	++i;}
    printf("\n"); break;
    }
    return 0;
}


/* ***************** main **************************** */
    int main(void){
	int n=0;
	int loop[9]= {
	    128128,128192,128256,192128,192192,192256,256128,256192,256256};
	
	while (n < 9){ 

	    
/* key generate & key display */
	    MakeKey();  
	    Key_out(key,loop[n]);
	    	    
/* plain data */
	    TestData(statemt,loop[n]);
 
/* encrypto */
	    encrypt(statemt,key,loop[n]);
	    
/* decrypto */
	    decrypt(statemt,key,loop[n]);
	    
	    printf("\n");
	    n++;   
	}
	statemt[0]  = 50;statemt[1] = 67;statemt[2] = 246;
	statemt[3] = 168;statemt[4] = 136;statemt[5] = 90;
	statemt[6] = 48;statemt[7] = 141;statemt[8] = 49;
	statemt[9] = 49;statemt[10] = 152;statemt[11]= 162;
	statemt[12] = 224;statemt[13] = 55;statemt[14]=7;statemt[15] = 52;
	
	key[0]=43;key[1]=126;key[2]=21;key[3]=22;key[4]=40;
	key[5]=174;key[6]=210;key[7]=166;key[8]=171;key[9]=247;key[10]=21;
	key[11]=136;key[12]=9;key[13]=207;key[14]=79;key[15]=60;

	encrypt(statemt,key,128128);
	decrypt(statemt,key,128128);
	return 0;
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -