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

📄 a.cpp

📁 algorithm provide basic encryption/decryption using AES for with Secret Key.
💻 CPP
字号:
// a.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "AESEngine1.h"
#include  <MALLOC.H>
#include  <STRING.h>
byte* getBufferFromFile(const char* filename);
int main(int argc, char* argv[])
{
	

	byte mybuf[16];
	byte mykey[16];
	byte* key1 = getBufferFromFile("key.txt");
	byte* databuf = getBufferFromFile("data.txt");
	
	size_t sz = sizeof(key1);
	AESEngine1* aesEngine = new AESEngine1();
	//byte data[10] = {0x31  ,0x32  ,0x33  ,0x34  ,0x35  ,0x36  ,0x37  ,0x38  ,0x39  ,0x30} ; //  ,0x0a  ,0x0b  ,0x0c  ,0x0d  ,0x0e  ,0x0f};  
    //byte key[16]  = {0x31  ,0x31  ,0x31  ,0x31  ,0x31  ,0x31  ,0x31, 0x31, 0x31  ,0x31  ,0x31  ,0x31  ,0x31  ,0x31  ,0x31, 0x31} ;
//    byte key[16] = {0x01  ,0x01  ,0x01  ,0x01, 0x01  ,0x01  ,0x01  ,0x01,0x01  ,0x01  ,0x01  ,0x01, 0x01  ,0x01  ,0x01  ,0x01 } ; 

//    byte data[10]  = {0x01  ,0x02  ,0x03  ,0x04,0x05  ,0x06  ,0x07  ,0x08,0x09, 0x00 } ; 
					  
	

    
	byte* outData;
	aesEngine->init(key1,16,151);
	aesEngine->encrypt(databuf,16,outData);
	
	return 0 ;

}

byte* getBufferFromFile(const char* filename)
{
  FILE * pFile;
  long lSize;
  byte * buffer;
  size_t result;

  pFile = fopen (  filename , "rb" );
  if (pFile==NULL) {fputs ("File error",stderr); }

  // obtain file size:
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

  // allocate memory to contain the whole file:
  buffer = (byte*) malloc (sizeof(byte)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); }

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); }

  /* the whole file is now loaded in the memory buffer. */

  // terminate
  fclose (pFile);
  //free (buffer);
  return buffer;
}

⌨️ 快捷键说明

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