/** *@autho stardust *@time 2013-10-10 *@param 实现AES五种加密模式的测试 */ #include <iostream> using namespace std; //加密编码过程函数,16位1和0 int dataLen = 16; //需要加密数据的长度 int encLen = 4; //加密分段的长度 int encTable[4] = {1,0,1,0}; //置换表 int data[16] = {1,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0}; //明文 int ciphertext[16]; //密文 //切片加密函数 void encode(int arr[]) { for(int i=0;i<encLen;i++) { arr[i] = arr[i] ^ encTable[i]; } } //电码本模式加密,4位分段 void ECB(int arr[]) { //数据明文切片 int a[4][4]; int dataCount = 0; //位置变量 for(int k=0;k<4;k++) { for(int t=0;t<4;t++) { a[k][t] = data[dataCount]; dataCount++; } } dataCount = 0;//重置位置变量 for(int i=0;i<dataLen;i=i+encLen) { int r = i/encLen;//行 int l = 0;//列 int encQue[4]; //编码片段 for(int j=0;j<encLen;j++) { encQue[j] = a[r][l]; l++; } encode(encQue); //切片加密 //添加到密文表中 for(int p=0;p<encLen;p++) { ciphertext[dataCount] = encQue[p]; dataCount++; } } cout<<"ECB加密的密文为:"<<endl; for(int t1=0;t1<dataLen;t1++) //输出密文 { if(t1!=0 && t1%4==0) cout<<endl; cout<<ciphertext[t1]<<" "; } cout<<endl; cout<<"---------------------------------------------"<<endl
AES防盗加密算法
最新推荐文章于 2023-04-11 17:39:58 发布
本文深入探讨了AES(高级加密标准)的工作原理,包括其加密过程、密钥扩展和轮操作。详细介绍了AES如何确保数据安全,及其在现代网络安全中的重要应用。
摘要由CSDN通过智能技术生成