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


C++ Crypto::encrypt方法代码示例

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


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

示例1: encryptAndDecrypt

//
// This function makes a polymorphic call to both the encryption
// and decryption functions, displaying the phrase both before
// and after each.
//
void  encryptAndDecrypt(Crypto  &msg)
{
	cout << "Original - " << msg.phrase() << endl;
	cout << "           Level = " << msg.encryptionLevel() << endl;
	cout << "   # Conversions = " << msg.numConversions() << endl;

	//
	// Encrypt
	//
	msg.encrypt();
	cout << " Encrypt - " << msg.phrase() << endl;
	cout << "           Level = " << msg.encryptionLevel() << endl;
	cout << "   # Conversions = " << msg.numConversions() << endl;

	//
	// Decyrpt
	//
	msg.decrypt();
	cout << " Decrypt - " << msg.phrase() << endl;
	cout << "           Level = " << msg.encryptionLevel() << endl;
	cout << "   # Conversions = " << msg.numConversions() << endl;
}
开发者ID:kendraash,项目名称:EncryptionDecryption,代码行数:27,代码来源:main.cpp

示例2: main


//.........这里部分代码省略.........
		page->generate(id);
		cout << ". OK" << endl << endl;

		delete page;
		exit(0);
	}

	if (enc) {
		cout << "[I] Encrypted msg:" << endl;

		Page   * page   = new Page;
		Crypto * crypto = new Crypto;

		// Get a usable page
		pnum = page->next(id);
		if (pnum == -1) {
			cout << "[E] Not found pages in book: " << id << endl;
			cout << "[I] You can generate them with: otpnitro -g -r " << id << endl << endl;
			exit(1);
		}

		// Read page X from Book (RECV ID)
		string out = page->read(pnum,id);

		if (msg.size() > out.size())
		{
			cout << "You need " << msg.size() - out.size() << " more bytes in the selected book page";
		        delete page;
		        delete crypto;
		        exit(1);
		}

		// Crypto
		string encrypted = crypto->encrypt(msg,out);

		// Print page
		Text * txt = new Text;
		txt->create(pnum,id,send,encrypted);
		cout << txt->print(1);

		delete txt;
		delete page;
		delete crypto;
		exit(0);
	}

	if (dec) {
		cout << "[I] Decrypted msg:" << endl;

		Page   * page   = new Page;
		Crypto * crypto = new Crypto;
		Text   * txt    = new Text;

		if (file.length() > 0)
			txt->parse(file);
		else
			txt->create(pnum,id,send,msg);

		// Read page X from Book (RECV ID)
		string out = page->read(txt->page,txt->book);

		if (out.length() == 0) {
			cout << "[E] The page " << pnum << " in the book " << id << " dont exist." << endl;
			cout << "[I] You can check if you recieved the " << id << " book, or if it was burned." << endl;
			cout << "[I] Check: otpnitro -l" << endl << endl;
			exit(1);
开发者ID:capitanx,项目名称:otpnitro,代码行数:67,代码来源:otpnitro.cpp

示例3: main

int main()
{
    
    Crypto* trans;
    Crypto* trans2;
    Crypto* trans3;
    Crypto* trans4;

    string org_msg;
    string enc_msg;
    string dec_msg;

    // - - - - - -
    // Ceasar
    // - - - - - -

    try
    {
        trans = Crypto::getCrypto("caesar", "5");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }

    org_msg = "Pull the brown book on the top shelf to activate";
    enc_msg = trans->encrypt(org_msg);
    dec_msg = trans->decrypt(enc_msg);

    cout << "Caesar: original message: \"" << org_msg << "\"" << endl;
    cout << "Caesar: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Caesar: decoded message: \"" << dec_msg << "\"" << endl << endl;

    delete trans;
    trans = 0;          // sets pointer to zero to avoid potential problems with dangling pointers

    // - - - - - -
    // Monoalpha
    // - - - - - -

    try
    {
        trans2 = Crypto::getCrypto("monoalpha", "QA Zwsxedcrfvtgbyhnujmikolp");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }

    org_msg = "Pull the brown book on the top shelf to activate";
    enc_msg = trans2->encrypt(org_msg);
    dec_msg = trans2->decrypt(enc_msg);

    cout << "Monoalpha: original message: \"" << org_msg << "\"" << endl;
    cout << "Monoalpha: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Monoalpha: decoded message: \"" << dec_msg << "\"" << endl << endl;

    delete trans2;
    trans2 = 0;

    // - - - - - -
    // Transposition
    // - - - - - -

    try
    {
        trans3 = Crypto::getCrypto("transposition", "240153");
    }
    catch(InvalidKeyException e)
    {
        exit(-1);
    }


    org_msg = "The password for today is deceptive";
    enc_msg = trans3->encrypt(org_msg);
    dec_msg = trans3->decrypt(enc_msg);

    cout << "Transposition: original message: \"" << org_msg << "\"" << endl;
    cout << "Transposition: encoded message: \"" << enc_msg << "\"" << endl;
    cout << "Transposition: decoded message: \"" << dec_msg << "\"" << endl << endl;

    string s1 = "test transposition with same object";
    string s2 = trans3->encrypt(s1);
    string s3 = trans3->decrypt(s2);

    cout << "Transposition: original message: \"" << s1 << "\"" << endl;
    cout << "Transposition: encoded message: \"" << s2 << "\"" << endl;
    cout << "Transposition: decoded message: \"" << s3 << "\"" << endl << endl;


    delete trans3;
    trans3 = 0;

    // - - - - - - - - 
    // Cencryption 
    // - - - - - - - -
    try
    {
        trans4 = Crypto::getCrypto("cencryption", "caesar,16,50;transposition,30142,50;caesar,21,30;");
//.........这里部分代码省略.........
开发者ID:klevstul,项目名称:CSE-4001-OO,代码行数:101,代码来源:test.cpp


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