C言語で、暗号化されたバイト配列のXORを移動させることにより、

職場での最近のデータ・セキュリティ・モジュールは、使用されるいくつかの非常に巧妙なシフト、XOR暗号化は程度の記録の下に、非常に良いです。

1、暗号化されたコード 

パラメータ平文平文、plaintext_size = 64、暗号文の暗号文、ciphertext_size = 128

int fake_rsa_encrypt(
	const unsigned char* plaintext,
	unsigned int plaintext_size,
	unsigned char *ciphertext,
	size_t *ciphertext_size)
{
	struct timeval time;
	gettimeofday(&time, NULL);
	// microsecond has 1 000 000
	// Assuming you did not need quite that accuracy
	// Also do not assume the system clock has that accuracy.
	srand((time.tv_sec * 1000) + (time.tv_usec / 1000));
	if ((plaintext_size < 128) && (!(plaintext_size & 3))) {
		int i, j;
		for (i = 0; i < (int)(128 - plaintext_size); i += 4) {
			long rdm = random();
			ciphertext[i + 0] = (rdm >> 24) & 0xff;
			ciphertext[i + 1] = (rdm >> 16) & 0xff;
			ciphertext[i + 2] = (rdm >> 8) & 0xff;
			ciphertext[i + 3] = (rdm)& 0xff;
		}
		for (i = 128 - plaintext_size, j = 0; i < 128; ++i, ++j) {
			ciphertext[i] = plaintext[j] ^ ciphertext[j];
		}
	}
	else {
		return -1;
	}
	*ciphertext_size = 128;
	return 0;
}

注:!(Plaintext_size&3)が非ゼロかどうかを決定する手段と、次の文書ポータルを参照してください&操作(ビット演算)

コードがセクションを持っています 

struct timeval time;
gettimeofday(&time, NULL);
// microsecond has 1 000 000
// Assuming you did not need quite that accuracy
// Also do not assume the system clock has that accuracy.
srand((time.tv_sec * 1000) + (time.tv_usec / 1000));

このコードの意味は、ランダムシードとして現在時刻が、その後、次のコードで乱数を取得するということです

    long rdm = random();

 使用される上記の二つの方法で、次に乱数を取得し、提供される固有のシード番号を使用する必要があります。

図2に示すように、復号化コード 

パラメータ暗号文暗号文、平文平文、plaintext_size = 64

int fake_rsa_decrypt(
	const unsigned char* ciphertext,
	unsigned char *plaintext,
	size_t *plaintext_size)
{
	*plaintext_size = 64;
	if (((*plaintext_size) < 128) && (!((*plaintext_size) & 3))) {
		int i;
		for (i = 0; i < (int)(*plaintext_size); i++) {
			plaintext[i] = ciphertext[128 - (*plaintext_size) + i] ^ ciphertext[i];
		}
	}
	else {
		return -1;
	}
	return 0;
}

繊細64に記憶された彼の元の64ビットの乱数列は、排他的OR演算のアレイ、64ビット、第64ビットで保存暗号文は、128ビットの暗号文アレイであるXOR非常に巧妙で、配列を暗号化する前に平文で渡すことができます。

公開された352元の記事 ウォンの賞賛390 ビュー370 000 +

おすすめ

転載: blog.csdn.net/qq_19734597/article/details/102504820