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


C++ encrypt函数代码示例

本文整理汇总了C++中encrypt函数的典型用法代码示例。如果您正苦于以下问题:C++ encrypt函数的具体用法?C++ encrypt怎么用?C++ encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

int main()
{
	system("cls");
	do
	{
		// requests prime number from the user.
	printf("Enter a prime number: ");			
	scanf("%d",&ptest);
		// checks if it is prime before assigning it to the 'p' variable.
	flag=prime(ptest);
	}while(flag==0);
	if(flag==1)
	p=ptest;
	do
	{
		// requests another prime number from the user.
	printf("\nEnter a second prime number: ");
	scanf("%d",&qtest);
		// checks if it is prime before assigning it to the 'q' variable.
	flag=prime(qtest);
	}while(flag==0);
	if(flag==1)
	q=qtest;
		// gets the message from the user.
	printf("\nEnter message: ");
	fflush(stdin);
	scanf("%[^\n]%*c",Msg);
	len=strlen(Msg);
	for(i=0;i!=len;i++)
	m[i]=Msg[i];
		// calculates the modulus and phi.
	n=p*q;
	phi=(p-1)*(q-1);
		// then e and d.
	calcE();
	printf("\nPossible values of e and d: ");
	for(i=0;i<j-1;i++)
	printf("\n%ld\t%ld",e[i],d[i]);
	encrypt();
	decrypt();
	getch();
	return(0);
}
开发者ID:sharebear42,项目名称:crypto,代码行数:43,代码来源:RSA.c

示例2: fwrite

void Test_encrypt::stringUnderThanMatrix()
{
	input=fopen("test.txt","w+");
	char string[50]="Example text for testing this algorithm";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[5]={0,2,4,3,1};
	encrypt(5,8,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"Elxrttaia  tnighpeos  r\0mtfegsomxet inlt");
	fclose(output);
}
开发者ID:Chitatsu,项目名称:Encryptor,代码行数:19,代码来源:Test_encrypt.cpp

示例3: encrypt

cryptor &cryptor::get(char *buf,
                      int max_length,
                      istream &is,
                      int &more,
                      char terminator)
{
  is.get(buf, max_length, terminator);
  if (is.peek() == terminator)
  {
    is.get();
    more = 0;
  }
  else
    more = 1;

  encrypt(buf);

  return *this;
}
开发者ID:nmathewson,项目名称:aptor1995,代码行数:19,代码来源:CRYPT.CPP

示例4: main

int main()
{
	//nb表示分组长度;nk表示密钥长度
	int i,nb,nk;
	char str[]="abcd1234567890123456789012345678901212345678901234567890123456789012";
    char key[32];
	char block[32];
	gentables();
	strtoHex(str,key);
	hextoStr(key,str);
	printf("Key=");
	for (i=0;i<64;i++)
		printf("%c",str[i]);
	printf("\n");
	for (i=0;i<32;i++)
		block[i]=i;
	for (nb=4;nb<=8;nb+=2)
		for (nk=4;nk<=8;nk+=2)
		{
			printf("\nBlock Size= %d bits, Key Size= %d bits\n",nb*32,nk*32);
			gkey(nb,nk,key);
			printf("Plain= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",block[i]);
			printf("\n");
			//进行加密
			encrypt(block);
			//输出密文
			printf("Encrypt= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",(unsigned char)block[i]);
			printf("\n");
			//进行解密
			decrypt(block);
			//输出明文
			printf("Decrypt= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",block[i]);
			printf("\n");
		}
		system("pause");
		return 0;
}
开发者ID:RUIXUEZHAOFENGNIAN,项目名称:mycode,代码行数:43,代码来源:AES加解密算法1.cpp

示例5: encryptMessage

static inline uint8_t encryptMessage(struct Message* message,
                                     struct Wrapper* wrapper)
{
    assert(message->padding >= 36 || !"not enough padding");

    encrypt(wrapper->nextNonce,
            message,
            wrapper->secret,
            wrapper->isInitiator,
            wrapper->authenticatePackets);

    Message_shift(message, 4);

    union Headers_CryptoAuth* header = (union Headers_CryptoAuth*) message->bytes;
    header->nonce = Endian_hostToBigEndian32(wrapper->nextNonce);
    wrapper->nextNonce++;

    return wrapper->wrappedInterface->sendMessage(message, wrapper->wrappedInterface);
}
开发者ID:Ralith,项目名称:cjdns,代码行数:19,代码来源:CryptoAuth.c

示例6: main

int main() {
	char cxt[512] = {0};
	byte key[] = "hello, worldxxyy";
	byte pt[] = "this is the plaintext";
	byte ct[32] = {0};
	byte pt2[32] = {0};

	aes.set_key(cxt, key, 16);
	encrypt(cxt, pt, sizeof(pt), ct);
	printf("cipher text:\n");
	hexdump(ct, 32);

	decrypt(cxt, ct, 32, pt2);
	printf("decrypted text:\n");
	hexdump(pt2, 32);
	printf("%s\n", pt2);

	return 0;
}
开发者ID:GaloisInc,项目名称:llvm-verifier,代码行数:19,代码来源:aes-driver.c

示例7: fileStream

/**
 * @brief Writes to file associated with the calling object. If a valid key
 *        is available, data is encrypted (AES-GCM) prior to writing.
 *
 * @param ss const reference to a string stream with data.
 * @param key const reference to a byte vector with the encryption key.
 *
 * @return true, if data was sucessfully written to file.
 */
bool FileCryptopp::writeFile(
    const std::stringstream& ss,
    const std::vector<uint8_t>& key
) {

    // Start a file stream.
    std::ofstream fileStream(_filename, std::ios::binary);

    // Check if file stream is open.
    if (!fileStream.is_open()) {
        return false;
    }

    // Initialize an ostream_iterator to write to the file stream.
    std::ostream_iterator<uint8_t> oit(fileStream);

    // Check if encyption key is provided.
    if (!key.empty()) {
        // Check if encryption key has length equal to default AES key length.
        if (key.size() != FileCryptopp::AESNODE_DEFAULT_KEY_LENGTH_BYTES) {
            // Invalid key.
            std::cout << "Invalid key length";
            return false;
        }

        // Vector to store encrypted bytes of data.
        std::vector<uint8_t> cipherData;

        // Attempt to encrypt input stream ss and load bytes into cipherData.
        if (!encrypt(ss, cipherData, key)) {
            // Failed encryption.
            return false;
        }
        // Write encrypted bytes from cipherData to file as chars.
        std::copy(cipherData.begin(), cipherData.end(), oit);
    } else {
        // Write to file without encryption.
        fileStream << ss.str();
    }

    fileStream.close();
	return true;
}
开发者ID:kleopatra999,项目名称:seifrng,代码行数:52,代码来源:fileCryptopp.cpp

示例8: strlen

/*
 * encrypt(keySize,password,original_message,encrypted_message, mode, padding)
 * - encrypts a message using AES Algorithm
 *
 * Parameters:
 *    keySize : Size of key to use in AES Algorithm
 *    password: Key to encrypt plaintext message.
 *    original_message: Plaintext message before calculating AES Algorithm
 *    encrypted_message: Ciphertext message after calculating AES Algorithm
 *    mode: cipher mode, two ways: ECB
 *    padding: padding mode to fill blocks, tree ways PKCS5, ZEROS, X923
 *
 * Examples:
 *  AES.encrypt(128,"libelium","Libelium",encrypted_message,ECB,PKCS5)
 *
 */
uint8_t WaspAES::encrypt(	uint16_t keySize
							, char* password
							, char original_message[]
							, uint8_t* encrypted_message
							, uint8_t mode
							, uint8_t padding)
{
	// Calculate length of the original message
	uint16_t original_length;
	original_length = strlen(original_message);

	return encrypt(	keySize,
					password,
					(uint8_t*) original_message,
					original_length,
					encrypted_message,
					mode,
					padding);	
}
开发者ID:AppSaloon,项目名称:waspmoteapi,代码行数:35,代码来源:WaspAES.cpp

示例9: main

int main(int argc, string argv[])
{
    //validate command line args
    if (argc != 2)
    {
        printf("You must supply at minimum and at most one command line argument. e.g. ./caeser 4. PLEASE TRY AGAIN!!!!\n");
        return 1;
    }

    //convert string input to int
    int rotateBy = atoi(argv[1]);

    string plainTextMessage = GetString();

    for(int i = 0, len = strlen(plainTextMessage); i < len; i++){
        printf("%c", encrypt(plainTextMessage[i], rotateBy));
    }
    printf("\n");
}
开发者ID:tschf,项目名称:scratch,代码行数:19,代码来源:caesar.c

示例10: encrypt_cmd

static TACommandVerdict encrypt_cmd(TAThread thread,TAInputStream stream)

{

    char* block;

    int edflag;

   

    // Prepare

    block=(char*)readPointer(&stream);

    edflag=readInt(&stream);



    START_TARGET_OPERATION(thread);

    errno=0;

    encrypt(block, edflag);

    END_TARGET_OPERATION(thread);



    // Response

    writePointer(thread, block);

    writeInt(thread, errno);



    sendResponse(thread);

    

    return taDefaultVerdict;

}
开发者ID:levenkov,项目名称:olver,代码行数:43,代码来源:crypt_agent.c

示例11: f5star

void f5star(u8* keyArr, u8* sqn_ak) {
    u8* out5;
    out5 = malloc(16);

    for (i = 0; i < 16; i++) {
        out5[i] = temp[i] ^ opc[i];
    }
    
    convertToBin(out5, binArr);
    rotWord(binArr, 128, 0x08);
    convertToHex(binArr, out5);

    for (i = 0; i < 16; i++) {
        out5[i] ^= c5[i];
    }
    encrypt(out5, keyArr, out5);

    for (i = 0; i < 16; i++) {
        out5[i] ^= opc[i];
    }

    printf("\r\nAK (f5*): ");
    for (i = 0; i < 6; i++) {
        ak[i] = out5[i];
        printf("%02x", ak[i]);
    }
    
    for (i = 0; i < 6; i++) {
        sqn[i] = ak[i] ^ sqn_ak[i];
    }
    
    u8 ind = (sqn[5] & 0b00011111);
    u8 seq = (sqn[5] & 0b11100000);
    ind = (ind + 1) % 32;
    sqn[5] = 0;
    sqn[5] |= ind;
    
    seq += 0b00100000;
    if (seq == 0) {
        sqn[4] += 1;
    }
    sqn[5] |= seq;
}
开发者ID:sim-authentication,项目名称:document,代码行数:43,代码来源:milenage.c

示例12: memcpy

void SparkProtocol::variable_value(unsigned char *buf,
                                   unsigned char token,
                                   unsigned char message_id_msb,
                                   unsigned char message_id_lsb,
                                   double return_value)
{
  buf[0] = 0x61; // acknowledgment, one-byte token
  buf[1] = 0x45; // response code 2.05 CONTENT
  buf[2] = message_id_msb;
  buf[3] = message_id_lsb;
  buf[4] = token;
  buf[5] = 0xff; // payload marker

  memcpy(buf + 6, &return_value, 8);

  memset(buf + 14, 2, 2); // PKCS #7 padding

  encrypt(buf, 16);
}
开发者ID:adeeshag,项目名称:particle_project,代码行数:19,代码来源:spark_protocol.cpp

示例13: main

void main()
{	struct block data,key,temp;
	//unsigned char c1[16]={0x32,0x88,0x31,0xe0,0x43,0x5a,0x31,0x37,0xf6,0x30,0x98,0x07,0xa8,0x8d,0xa2,0x34};
	//unsigned char c2[16]={0x2b,0x28,0xab,0x09,0x7e,0xae,0xf7,0xcf,0x15,0xd2,0x15,0x4f,0x16,0xa6,0x88,0x3c};
	unsigned char c1[16]="Hello World. 123";
	unsigned char c2[16]="My New Password.";	
	int i,j,c=0;
	struct block round_key[11];
	// Initializing Data and Key
	for(i=0;i<4;i++)
	{	for(j=0;j<4;j++)
		{	data.b[i][j]=c1[c];
			key.b[i][j]=c2[c];
			c++;	
		}
	}

	printf("Data and key before encryption:");
	printf("\n Data:\n");
	print_block(data);
	printf("\n Key:\n");
	print_block(key);

	printf("Generating All the round Keys:");
	round_key[0]=key;
	temp=key;	
	for(i=0;i<10;i++)
	{	temp=next_key(temp,i);
		round_key[i+1]=temp;
	}
	printf("All the keys generated.");

	data=encrypt(data,round_key);

	printf("Data after encryption:");
	printf("\n Data:\n");
	print_block(data);

	printf("\nData After Decryption\n");
	data=decrypt(data,round_key);
	print_block(data);
}
开发者ID:WayWingsDev,项目名称:CryptoLibAES-128,代码行数:42,代码来源:test.c

示例14: main

int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		showHelpAndExitWithCode(1);
	}

	// modernize the arguments, because passing arrays is a nightmare
	std::vector<std::string> args(argv, argv + argc);

	try 
	{
		for (int i = 0; i < args.size(); i++)
		{
			if (args.at(i).compare("-e") == 0)
			{
				encrypt(args, i);
				break;
			} 
			if (args.at(i).compare("-d") == 0)
			{
				decrypt(args, i);
				break;
			} 
			if (args.at(i).compare("-a") == 0)
			{
				analyze(args, i);
				break;
			} 
			if (i == args.size() - 1)
			{
				showHelpAndExitWithCode(1);
			}
		}
	}
	catch (std::runtime_error &ex)
	{
		std::cout << ex.what() << std::endl;
	}

	return 0;
}
开发者ID:akiraaisha,项目名称:steganographizer,代码行数:42,代码来源:main.cpp

示例15: SecureStorage_RemoveItem

bool SecureStorage_RemoveItem(const SecureStorageS *storage, const unsigned char *sKey, int16_t keyLen) {
  int16_t saltLen = 0;
  bool ret = false, ret1 = false;
  unsigned char *caEncKey = NULL, *rKey = NULL, *caKey = NULL;
  unsigned char cahKey[SHA256_LEN + UTILS_STR_LEN_SIZE + 1];

  if (storage == NULL || sKey == NULL) {
    snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: Storage and key must not be NULL");
    return false;
  }
  if (keyLen <= 0) {
    snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: key len %d must be positives\n", keyLen);
    return false;
  }
  if (READABLE_STORAGE == true)
    saltLen = 0;
  else if (Utils_GetCharArrayLen(storage->caSalt, &saltLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false)
    return false;
  if (generateAlignedCharAray(sKey, keyLen, storage->caSalt, saltLen, &caKey) == false) return false;
  if (isLengthValid(caKey, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN - 1) == false || getRandomFromKey(storage, caKey, cahKey, &rKey) == false) {
    Utils_Free(caKey);
    return false;
  }
  ret1 = clearKey(storage, cahKey);
  if (ret1 == false) { // continue to try to remove the "real" key value
    snprintf(errStr, sizeof(errStr), "Error: key for random '%s' was not found", cahKey);
  }
  ret = encrypt(caKey, rKey, storage->caSecret, &caEncKey);
  Utils_Free(rKey);
  if (ret == false) {
    Utils_Free(caKey);
    return false;
  }
  if (clearKey(storage, caEncKey) == false) {
    Utils_Free(caEncKey);
    snprintf(errStr, sizeof(errStr), "Error: key '%s' was not found", caKey);
    return false;
  }
  Utils_Free(caKey);
  Utils_Free(caEncKey);
  return ret1;
}
开发者ID:ibm-security-innovation,项目名称:libsecurity-c,代码行数:42,代码来源:secureStorage.c


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