当前位置: 首页>>代码示例>>C++>>正文


C++ AES::setCT方法代码示例

本文整理汇总了C++中AES::setCT方法的典型用法代码示例。如果您正苦于以下问题:C++ AES::setCT方法的具体用法?C++ AES::setCT怎么用?C++ AES::setCT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AES的用法示例。


在下文中一共展示了AES::setCT方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	AES* AESCipher = NULL;
	string msg;
	string key;
	char* temp_msg_hex;
	char* temp_key_hex;
	int mode = -1;

	while (mode != 0 && mode != 1) {
		cout << "Please choose the AES mode (0 for CBC, 1 for CTR): ";

		cin >> mode;
		
		switch (mode) {
		case 0:
			AESCipher = new AES128CBC();
			break;
		case 1:
			AESCipher = new AES128CTR();
			break;
		}

		cin.clear();
		cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
	}

	if (NULL == AESCipher) {
		cout << "Error allocating memory for cipher engine, program exiting...\n";
		return 0;
	}

	cout << "please provide the key: ";
	cin >> key;

	cout << "please provide the message text: ";
	cin >> msg;
	
	temp_key_hex = new char[key.length() + 1];
	for (int i = 0; i < key.length(); i++) {
		temp_key_hex[i] = key.c_str()[i];
	}
	temp_key_hex[key.length()] = 0;

	temp_msg_hex = new char[msg.length() + 1];
	for (int i = 0; i < msg.length(); i++) {
		temp_msg_hex[i] = msg.c_str()[i];
	}
	temp_msg_hex[msg.length()] = 0;

	AESCipher->setKey(temp_key_hex);

	mode = -1;
	while (/* mode != 0 && */ mode != 1) {
		cout << "Please choose whether you want to encrypt or decrypt (1 for decrypt, encrypt is not ready): ";
		cin >> mode;

		switch (mode) {
		case 0:
			AESCipher->setPT(temp_msg_hex);
			AESCipher->Encrypt();
			break;
		case 1:
			AESCipher->setCT(temp_msg_hex);
			AESCipher->Decrypt();
			break;
		}

		cin.clear();
		cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
	}


	return 0;
}
开发者ID:Morrandir,项目名称:Crypto001_Week2,代码行数:75,代码来源:main.cpp


注:本文中的AES::setCT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。