コード例 #1
0
void DEC3_Decrypt(unsigned char *miwen, unsigned char *out_buf)
{
	unsigned char buf1[8],buf2[8];

    DES_Decrypt(&DES_key[0],miwen,buf1);
	DES_Encrypt(&DES_key[8],buf1,buf2);
    DES_Decrypt(&DES_key[0],buf2,out_buf);
}
コード例 #2
0
void IntroPage::decrypt(){
  component_selection user_choice;

  QString input_file = ui ->cipher_file_path->text();
  QString output_file = ui ->decrypt_file_path ->text();
  std::string input_file_str = input_file.toStdString();
  std::string output_file_str = output_file.toStdString();

  //open binary setting file
  std::string file_name = (input_file + "_setting.dat").toStdString();
  std::ifstream infile(file_name.c_str(), std::ifstream::binary);
  if(infile.is_open()){
      infile.read(reinterpret_cast<char*>(&user_choice), sizeof(user_choice));
      infile.close();
    }
  else{
      QMessageBox::critical(this, "error", "cannot read binary setting file!");
      return;
    }


  int ret = DES_Decrypt(input_file_str.c_str(), user_choice.password,
                        output_file_str.c_str(), &user_choice);

  if(ret == 1){//OK
    QMessageBox::information(this, "info", "file decrypted!");
    }
  else if(ret == -3){//cipher file error
      QMessageBox::critical(this, "error", "cannot read cipher file!");
    }
  else if(ret == -1){//plain file error
      QMessageBox::critical(this, "error", "cannot write to plain file!");
    }
}
コード例 #3
0
ファイル: alchemyAes.c プロジェクト: kaelliu/Miscellaneous
AS3_Val doUnAes(void *data, AS3_Val args)
{
	AS3_Val input = NULL;
    unsigned int in_len;
	char * ar;
	AS3_ArrayValue(args, "AS3ValType, IntType", &input, &in_len);
	ar = (char *)malloc(in_len);
	
	AS3_ByteArray_readBytes((void*)ar, input, in_len);
		
	char * aesData;
	int out_len = 0;
	char * keyStr = "kael";
	
	//use AES to Decrypt the bytes	
	aesData = DES_Decrypt(ar, keyStr, in_len, &out_len );

	//make a new as3 byteArray var
	AS3_Val baNS = AS3_String("flash.utils");
	AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray");
	AS3_Val emptyParams = AS3_Array("");
	AS3_Val byteArray2 = AS3_New(baClass, emptyParams);
	
	AS3_ByteArray_writeBytes(byteArray2, aesData, out_len);
	return byteArray2;
}
コード例 #4
0
int main( void )
{
	bool success = true;

	/* Example of how to use Single DES encryption and decryption functions. */
	DES_Encrypt(indata, cipherdata, deskey);
	DES_Decrypt(cipherdata, outdata, decryptkey);

	/* Check if decrypted answer is equal to plaintext. */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != outdata[i]){
			success = false;
			break;
		}
	}

	if (success){
	  	while (true){
		/* If the example ends up here everything is ok. */
             nop();
		}
	}else{
		while (true){
		/* If the example ends up here something is wrong. */
             nop();
		}
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: tomatoXu/DES-key-test
int main()
{	
	clock_t a,b;
	a = clock();
        int key_creat[64];
        key(key_creat);
        char *plain;
        char *cipher;
        char *decrypted_mes;
        char plain_input[256]="";
        char cipher_output[256]="";
        char message[256]="";
        int i = 0;
        printf("please input the content to be encrypted:\n");
        scanf("%s",plain_input);
	DES_Encrypt(plain_input,key_creat,cipher_output);
	b = clock();
	printf("\n加密消耗%d毫秒\n",b-a);
	cipher = cipher_output;
        printf("\nthe encrypted message is:\n");
        for(i=0;i<strlen(cipher);i++){
                printf("0x%08x ",cipher_output[i]);
        }
//	system("pause");
	a = clock();
	DES_Decrypt(cipher_output,key_creat,message);
	b = clock();
	printf("\n解密消耗%d毫秒\n",b-a);
        decrypted_mes=message;
        printf("\nthe decrypted message:\n%s\n",decrypted_mes);
	getchar();
	return 0;
}
コード例 #6
0
void DEC3_Encrypt(unsigned char *in_buf, unsigned char *miwen)
{
	unsigned char buf1[8],buf2[8];

	DES_Encrypt(&DES_key[0],in_buf,buf1);
    DES_Decrypt(&DES_key[8],buf1,buf2);
	DES_Encrypt(&DES_key[0],buf2,miwen);
}
コード例 #7
0
ファイル: task2.c プロジェクト: LaneTee/xmega-intro
int main( void )
{
	bool success = true;

	/* Example of how to use 3DES encryption and decryption functions. */
	DES_3DES_Encrypt(indata, cipherdata, deskeys);
	DES_3DES_Decrypt(cipherdata, outdata, deskeys);

	/* Check if decrypted answer is equal to plaintext. */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != outdata[i]){
			success = false;
			break;
		}
	}

	/* "Manual" 3DES decryption implenemtation */
	/* cipher -> DES_DK3 -> DES_EK2 -> DES_DK1 -> plaintext */

	DES_Decrypt();  /* Add Code */
	DES_Encrypt();  /* Add Code */
	DES_Decrypt();  /* Add Code */


	/* Check if this "manual" decrypt is equal to indata */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != des_stage_3[i]){
			success = false;
			break;
		}
	}

	if (success){
	  	while (true){
		/* If the example ends up here everything is ok. */
             nop();
		}
	}else{
		while (true){
		/* If the example ends up here something is wrong. */
             nop();
		}
	}
}
コード例 #8
0
ファイル: enfileTest.cpp プロジェクト: yzmin/Des
int main(int argc,char **argv)
{
	if(argc < 4)
	{
		printf("./enfile seckey enkey dekey\n");
		return -1;
	}	
	printf("开始加密!\n");
	DES_Encrypt(argv[1],"12345678",argv[2]);
	printf("加密完成!\n");	
	DES_Decrypt(argv[2],"12345678",argv[3]);
	printf("解密完成!\n");

	return 0;
}
コード例 #9
0
ファイル: des_demo.c プロジェクト: alexazhou/text-encrypt
int main()  
{     
	clock_t a,b;  
	char *key = "ABCDEFGH12345678";
	char tmp[100] ={0};
	char tmp_2[100] ={0};

	char *plainStr = "12345678abcdefgh1";
	long int n_plain,n_cipher = 0;
	
	a = clock();  
	DES_Encrypt("1.txt",key,"2.txt");  
	b = clock();  
	printf("¼ÓÃÜÏûºÄ%dºÁÃë\n",b-a);  
	  
	system("pause");  
	a = clock();  
	DES_Decrypt("2.txt",key,"3.txt");  
	b = clock();  
	printf("½âÃÜÏûºÄ%dºÁÃë\n",b-a);  
	getchar(); 
	

	DES_Encrypt_Data(plainStr,key,tmp,16);
	printf("data len is %d\n",n_cipher);

	
	DES_Decrypt_Data(tmp, key,tmp_2,16);
	
	printf("data decrypted is %s\n",tmp_2);
	

	getchar(); 
	
	return 0;  
}