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

📄 aes_dec.c

📁 该文件属于c++运行环境下AES加密程序源码。
💻 C
字号:
/* aes_dec.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 "aes.h"
int decrypt(int statemt[32],int key[32],int type){
    int i;
    KeySchedule(type,key);

  switch(type){
  case 128128:round = 10;nb=4;break;
  case 128192:case 192192:round=12;nb=6;break;
  case 192128:round=12;nb=4;break;
  case 128256:case 192256:round=14;nb=8;break;
  case 256128:round = 14;nb=4;break;
  case 256192:round = 14;nb=6;break;
  case 256256:round = 14;nb=8;break;
  }

  AddRoundKey(statemt,type,round);
  InversShiftRow_ByteSub(statemt,nb);

  for (i=round-1;i>9;--i){
  AddRoundKey_InversMixColumn(statemt,nb,i);
      InversShiftRow_ByteSub(statemt,nb);}

  AddRoundKey_InversMixColumn(statemt,nb,9);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,8);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,7);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,6);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,5);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,4);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,3);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,2);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,1);
  InversShiftRow_ByteSub(statemt,nb);

  AddRoundKey(statemt,type,0);  

	printf("decrypto message\t");
	for (i=0;i<((type % 1000) / 8);++i){
	    if (statemt[i] < 16) printf("0");
	    printf("%x",statemt[i]);
	}
	printf("\n");
    return 0;
}

/*  ********** no  out *************** */
int decrypto(int statemt[32],int key[32],int type){
  int i;

  switch(type){
  case 128128:round = 10;nb=4;break;
  case 128192:case 192192:round=12;nb=6;break;
  case 192128:round=12;nb=4;break;
  case 128256:case 192256:round=14;nb=8;break;
  case 256128:round = 14;nb=4;break;
  case 256192:round = 14;nb=6;break;
  case 256256:round = 14;nb=8;break;
  }

  AddRoundKey(statemt,type,round);
  InversShiftRow_ByteSub(statemt,nb);

  for (i=round-1;i>9;--i){
  AddRoundKey_InversMixColumn(statemt,nb,i);
      InversShiftRow_ByteSub(statemt,nb);}

  AddRoundKey_InversMixColumn(statemt,nb,9);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,8);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,7);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,6);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,5);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,4);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,3);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,2);
  InversShiftRow_ByteSub(statemt,nb);
  AddRoundKey_InversMixColumn(statemt,nb,1);
  InversShiftRow_ByteSub(statemt,nb);

  AddRoundKey(statemt,type,0);  

  return 0;
}

⌨️ 快捷键说明

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