亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? des.c

?? des加密算法 des加密算法 des加密算法 解密
?? C
字號(hào):
#include <stdlib.h>
#include <stdio.h>

#define ENCRYPT 1
#define DECRYPT 0

typedef char bool;

// 16 sub keys
static bool SubKey[16][48];

// Permuted Choice 1 (PC-1)
const static char PC1_Table[56] =
{
	57, 49, 41, 33, 25, 17,   9,
		1, 58, 50, 42, 34, 26, 18,
		10,   2, 59, 51, 43, 35, 27,
		19, 11,   3, 60, 52, 44, 36,
		63, 55, 47, 39, 31, 23, 15,
		7, 62, 54, 46, 38, 30, 22,
		14,   6, 61, 53, 45, 37, 29, 
		21, 13,   5, 28, 20, 12,   4
};

// Left Shifts
const static char LOOP_Table[16] =
{
	1, 1, 2, 2, 2, 2, 2, 2,
		1, 2, 2, 2, 2, 2, 2, 1
};

// Permuted Choice 2 (PC-2)
const static char PC2_Table[48] =
{
	14, 17, 11, 24,   1,   5,
		3, 28, 15,   6, 21, 10,
		23, 19, 12,   4, 26,   8,
		16,   7, 27, 20, 13,   2,
		41, 52, 31, 37, 47, 55,
		30, 40, 51, 45, 33, 48,
		44, 49, 39, 56, 34, 53,
		46, 42, 50, 36, 29, 32
};

// Initial Permutation (IP)
const static char IP_Table[64] =
{
	58, 50, 42, 34, 26, 18, 10, 2,
		60, 52, 44, 36, 28, 20, 12, 4,
		62, 54, 46, 38, 30, 22, 14, 6,
		64, 56, 48, 40, 32, 24, 16, 8,
		57, 49, 41, 33, 25, 17,   9, 1,
		59, 51, 43, 35, 27, 19, 11, 3,
		61, 53, 45, 37, 29, 21, 13, 5,
		63, 55, 47, 39, 31, 23, 15, 7
};

// Expansion (E)
static const char E_Table[48] =
{
	32,   1,   2,   3,   4,   5, 
		4,   5,   6,   7,   8,   9,
		8,   9, 10, 11, 12, 13, 
		12, 13, 14, 15, 16, 17,
		16, 17, 18, 19, 20, 21, 
		20, 21, 22, 23, 24, 25,
		24, 25, 26, 27, 28, 29, 
		28, 29, 30, 31, 32,   1
};

// The (in)famous S-boxes
const static char S_Box[8][4][16] =
{
	{
		// S1 
		{14,   4, 13,   1,   2, 15, 11,   8,   3, 10,   6, 12,   5,   9,   0,   7},
		{ 0, 15,   7,   4, 14,   2, 13,   1, 10,   6, 12, 11,   9,   5,   3,   8},
		{ 4,   1, 14,   8, 13,   6,   2, 11, 15, 12,   9,   7,   3, 10,   5,   0},
		{15, 12,   8,   2,   4,   9,   1,   7,   5, 11,   3, 14, 10,   0,   6, 13}
	},
	{
		// S2 
		{15,   1,   8, 14,   6, 11,   3,   4,   9,   7,   2, 13, 12,   0,   5, 10},
		{ 3, 13,   4,   7, 15,   2,   8, 14, 12,   0,   1, 10,   6,   9, 11,   5},
		{ 0, 14,   7, 11, 10,   4, 13,   1,   5,   8, 12,   6,   9,   3,   2, 15},
		{13,   8, 10,   1,   3, 15,   4,   2, 11,   6,   7, 12,   0,   5, 14,   9}
	},
	{
		// S3 
		{10,   0,   9, 14,   6,   3, 15,   5,   1, 13, 12,   7, 11,   4,   2,   8},
		{13,   7,   0,   9,   3,   4,   6, 10,   2,   8,   5, 14, 12, 11, 15,   1},
		{13,   6,   4,   9,   8, 15,   3,   0, 11,   1,   2, 12,   5, 10, 14,   7},
		{ 1, 10, 13,   0,   6,   9,   8,   7,   4, 15, 14,   3, 11,   5,   2, 12}
	},
	{
		// S4 
		{ 7, 13, 14,   3,   0,   6,   9, 10,   1,   2,   8,   5, 11, 12,   4, 15},
		{13,   8, 11,   5,   6, 15,   0,   3,   4,   7,   2, 12,   1, 10, 14,   9},
		{10,   6,   9,   0, 12, 11,   7, 13, 15,   1,   3, 14,   5,   2,   8,   4},
		{ 3, 15,   0,   6, 10,   1, 13,   8,   9,   4,   5, 11, 12,   7,   2, 14}
	},
	{
		// S5 
		{ 2, 12,   4,   1,   7, 10, 11,   6,   8,   5,   3, 15, 13,   0, 14,   9},
		{14, 11,   2, 12,   4,   7, 13,   1,   5,   0, 15, 10,   3,   9,   8,   6},
		{ 4,   2,   1, 11, 10, 13,   7,   8, 15,   9, 12,   5,   6,   3,   0, 14},
		{11,   8, 12,   7,   1, 14,   2, 13,   6, 15,   0,   9, 10,   4,   5,   3}
	},
	{
		// S6 
		{12,   1, 10, 15,   9,   2,   6,   8,   0, 13,   3,   4, 14,   7,   5, 11},
		{10, 15,   4,   2,   7, 12,   9,   5,   6,   1, 13, 14,   0, 11,   3,   8},
		{ 9, 14, 15,   5,   2,   8, 12,   3,   7,   0,   4, 10,   1, 13, 11,   6},
		{ 4,   3,   2, 12,   9,   5, 15, 10, 11, 14,   1,   7,   6,   0,   8, 13}
	},
	{
		// S7 
		{ 4, 11,   2, 14, 15,   0,   8, 13,   3, 12,   9,   7,   5, 10,   6,   1},
		{13,   0, 11,   7,   4,   9,   1, 10, 14,   3,   5, 12,   2, 15,   8,   6},
		{ 1,   4, 11, 13, 12,   3,   7, 14, 10, 15,   6,   8,   0,   5,   9,   2},
		{ 6, 11, 13,   8,   1,   4, 10,   7,   9,   5,   0, 15, 14,   2,   3, 12}
	},
	{
		// S8 
		{13,   2,   8,   4,   6, 15, 11,   1, 10,   9,   3, 14,   5,   0, 12,   7},
		{ 1, 15, 13,   8, 10,   3,   7,   4, 12,   5,   6, 11,   0, 14,   9,   2},
		{ 7, 11,   4,   1,   9, 12, 14,   2,   0,   6, 10, 13, 15,   3,   5,   8},
		{ 2,   1, 14,   7,   4, 10,   8, 13, 15, 12,   9,   0,   3,   5,   6, 11}
	}
};

// Permutation P
const static char P_Table[32] =
{
	16,   7, 20, 21, 
		29, 12, 28, 17,
		1, 15, 23, 26,
		5, 18, 31, 10,
		2,   8, 24, 14,
		32, 27,   3,   9,
		19, 13, 30,   6,
		22, 11,   4, 25
};

// Final Permutation (IP**-1)
const static char IPR_Table[64] =
{
	40, 8, 48, 16, 56, 24, 64, 32,
		39, 7, 47, 15, 55, 23, 63, 31,
		38, 6, 46, 14, 54, 22, 62, 30,
		37, 5, 45, 13, 53, 21, 61, 29,
		36, 4, 44, 12, 52, 20, 60, 28,
		35, 3, 43, 11, 51, 19, 59, 27,
		34, 2, 42, 10, 50, 18, 58, 26,
		33, 1, 41,   9, 49, 17, 57, 25
};

// 主函數(shù)
void Des_SetKey(const char Key[8]);
void Des_Run(char Out[8], char In[8], bool Type);

// 功能函數(shù)
static void F_func(bool In[32], const bool Ki[48]);       // f 函數(shù)
static void S_func(bool Out[32], const bool In[48]);      // S 盒代替
static void Transform(bool *Out, bool *In, const char *Table, int len); // 變換
static void Xor(bool *InA, const bool *InB, int len);      // 異或
static void RotateL(bool *In, int len, int loop);       // 循環(huán)左移
static void ByteToBit(bool *Out, const char *In, int bits);     // 字節(jié)組轉(zhuǎn)換成位組
static void BitToByte(char *Out, const bool *In, int bits);     // 位組轉(zhuǎn)換成字節(jié)組

// 測(cè)試用
static void printHex( char *cmd, int len );
static void printArray( const char *In, int len );

int main(int argc, char *argv[])
{
	int i;
	char key[16];
	char str[16],str2[16];
	printf("Input Key:\n");
	for(i=0;i<16;i++)
		scanf("%c",&key[i]);
	getchar();
	printf("Input PlainText:\n");
	gets(str);
	
	//printArray( PC2_Table, sizeof(PC2_Table)/sizeof(PC2_Table[0]) );
	
	
	Des_SetKey(key);
	
	memset(str2, 0, sizeof(str2));
	Des_Run(str2, str, ENCRYPT);
	printf("CipherText:\n");
	printHex( str2, 8 );
	
	memset(str, 0, sizeof(str));
	printf("Decryption:\n");
	Des_Run(str, str2, DECRYPT);
	puts(str2);
	
	return 0;
}

// == 1. Process the key ==
void Des_SetKey(const char Key[8])
{
	int i;
	static bool K[64], *KL = &K[0], *KR = &K[28];
    
	ByteToBit(K, Key, 64);
    
	Transform(K, K, PC1_Table, 56);
    
	// 1.2.3 Calculate the 16 sub keys. Start with i = 1. 
	for(i=0; i<16; i++)
	{
		// 1.2.3.1 Perform one or two circular left shifts on both C[i-1] and D[i-1] to get C[i] and D[i], respectively. 
		RotateL(KL, 28, LOOP_Table[i]);
		RotateL(KR, 28, LOOP_Table[i]);
        
		// 1.2.3.2 Permute the concatenation C[i]D[i] as indicated below. This will yield K[i], which is 48 bits long.
		Transform(SubKey[i], K, PC2_Table, 48);
	}
}

// == 2. Process a 64-bit data block ==
void Des_Run(char Out[8], char In[8], bool Type)
{
	int i;
	static bool M[64], tmp[32], *Li = &M[0], *Ri = &M[32];
    
	// 2.1 Get a 64-bit data block. If the block is shorter than 64 bits, it should be padded as appropriate for the application. 
	ByteToBit(M, In, 64);
    
	// 2.2 Perform the following permutation on the data block. 
	Transform(M, M, IP_Table, 64);
    
	//2.3 Split the block into two halves. The first 32 bits are called L[0], and the last 32 bits are called R[0]. 
    
	if( Type == ENCRYPT )
	{
		// 2.4 Apply the 16 sub keys to the data block. Start with i = 1. 
		for(i=0; i<16; i++)
		{
			memcpy(tmp, Ri, 32);
            
			// R[i] = L[i-1] xor f(R[i-1], K[i])
			F_func(Ri, SubKey[i]);
            
			// 2.4.6 Exclusive-or the resulting value with L[i-1].
			// R[I]=P XOR L[I-1]
			Xor(Ri, Li, 32);
            
			// L[i] = R[i-1]
			memcpy(Li, tmp, 32);
            
		} //2.4.8 Loop back to 2.4.1 until K[16] has been applied. 
	}
	else
	{
		// To decrypt, use the same process
		// but just use the keys K[i] in reverse order
		for(i=15; i>=0; i--)
		{
			memcpy(tmp, Li, 32);
			F_func(Li, SubKey[i]);
			Xor(Li, Ri, 32);
			memcpy(Ri, tmp, 32);
		}
	}
	
	// 2.5 Perform the following permutation on the block R[16]L[16]. (Note that block R precedes block L this time.) 
	Transform(M, M, IPR_Table, 64);
    
	BitToByte(Out, M, 64);
}

void F_func(bool In[32], const bool Ki[48])
{
	static bool MR[48];
    
	// 2.4.1 Expand the 32-bit R[i-1] into 48 bits according to the bit-selection function below. 
	Transform(MR, In, E_Table, 48);
    
	// 2.4.2 Exclusive-or E(R[i-1]) with K[i]. 
	Xor(MR, Ki, 48);
    
	// 2.4.4 Substitute the values found in the S-boxes for all B[j]. Start with j = 1. All values in the S-boxes should be considered 4 bits wide. 
	S_func(In, MR);
    
	// 2.4.5 Permute the concatenation of B[1] through B[8] as indicated below. 
	Transform(In, In, P_Table, 32);
}

void S_func(bool Out[32], const bool In[48])
{
	char j,m,n;
	
	//2.4.3 Break E(R[i-1]) xor K[i] into eight 6-bit blocks. Bits 1-6 are B[1]... 
	for(j=0; j<8; j++,In+=6,Out+=4)
	{
		// 2.4.4.1 Take the 1st and 6th bits of B[j] together as a 2-bit value (call it m) indicating the row in S[j] to look in for the substitution. 
		m = (In[0]<<1) + In[5];
        
		// 2.4.4.2 Take the 2nd through 5th bits of B[j] together as a 4-bit value (call it n) indicating the column in S[j] to find the substitution.
		n = (In[1]<<3) + (In[2]<<2) + (In[3]<<1) + In[4];
        
		// 2.4.4.3 Replace B[j] with S[j][m][n]. 
		ByteToBit(Out, &S_Box[(int)j][(int)m][(int)n], 4);
	}
}

// -- Perform the permutation --
void Transform(bool *Out, bool *In, const char *Table, int len)
{
	int i;
	static bool tmp[256];
    
	for(i=0; i<len; i++)
	{
		tmp[i] = In[ Table[i]-1 ];
	}
	memcpy(Out, tmp, len);
}

// -- xor --
void Xor(bool *InA, const bool *InB, int len)
{
	int i;
	
	for(i=0; i<len; i++)
	{
		InA[i] ^= InB[i];
	}
}

// -- Perform one or two circular left shifts --
void RotateL(bool *In, int len, int loop)
{
	static bool tmp[256];    // Sample:
	// loop=2
	memcpy(tmp, In, loop);    // In=12345678 tmp=12
	memcpy(In, In+loop, len-loop); // In=345678   
	memcpy(In+len-loop, tmp, loop); // In=34567812
}

// Sample:
// In = [0x01]
// Out = [0x01] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00]
void ByteToBit(bool *Out, const char *In, int bits)
{
	int i;
	
	for(i=0; i<bits; i++)
	{
		// In[i]的第N位右移N位并和0x01按位"與"運(yùn)算(N=1~8)
		Out[i] = (In[i/8]>>(i%8)) & 1;
	}
}

void BitToByte(char *Out, const bool *In, int bits)
{
	int i;
	
	memset(Out, 0, (bits+7)/8);
	for(i=0; i<bits; i++)
	{
		Out[i/8] |= In[i]<<(i%8);
	}
}

// 打印指定位置指定長(zhǎng)度HEX值 
static void printHex( char *cmd, int len )
{
	int i;
	
	for(i=0; i<len; i++)
	{
		printf("%02X",(unsigned char)cmd[i]);
	}
	printf("\n");
}

// 打印數(shù)組測(cè)試用
//static void printArray( const char *In, int len )
//{
//	int   i;
//	char tmp[256];
	
//	memset(tmp, 0, sizeof(tmp));
	
//	for( i=0; i<len; i++)
//	{
//		tmp[(int)In[i]]=In[i];
//	}
	
//	for( i=0; i<len; i++)
//	{
//		printf("[%02d]",(unsigned char)tmp[i]);
//	}
//	printf("\n");
//}



?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品乱码亚洲一区二区不卡| 日韩欧美国产1| 狠狠色丁香久久婷婷综| 亚洲乱码国产乱码精品精的特点| 日韩午夜小视频| 91丝袜高跟美女视频| 色欧美片视频在线观看| 精品一区二区在线观看| 亚洲综合丁香婷婷六月香| 337p日本欧洲亚洲大胆精品| 欧美日韩激情一区二区三区| 一本久道久久综合中文字幕| 久久久久久久久一| 欧美少妇xxx| 成人av资源在线观看| 狠狠色丁香九九婷婷综合五月| 亚洲va国产天堂va久久en| 欧美三级电影精品| 东方欧美亚洲色图在线| 蓝色福利精品导航| 香蕉乱码成人久久天堂爱免费| 中文字幕乱码一区二区免费| 日韩免费观看2025年上映的电影| 欧美人成免费网站| 在线视频你懂得一区| 97久久精品人人做人人爽| 国产精品18久久久久久久久久久久| 久久精品国产免费| 毛片基地黄久久久久久天堂| 亚洲777理论| 亚洲第一会所有码转帖| 亚洲人成在线观看一区二区| 国产精品高潮呻吟| 亚洲欧洲日韩一区二区三区| 日本一区二区综合亚洲| 国产日韩高清在线| 国产女主播一区| 国产精品毛片大码女人| 国产精品日产欧美久久久久| 日本一区二区三区高清不卡| 中文字幕精品三区| 国产无人区一区二区三区| 99综合影院在线| 精品亚洲国内自在自线福利| 久久99国产精品久久99| 久久成人18免费观看| 久久不见久久见免费视频7| 九一九一国产精品| 国产米奇在线777精品观看| 国产乱一区二区| 国产+成+人+亚洲欧洲自线| 成人黄色综合网站| 91麻豆免费视频| 欧美性猛交xxxxxxxx| 欧美电影在线免费观看| 日韩亚洲国产中文字幕欧美| 亚洲精品一区二区三区四区高清| 久久婷婷久久一区二区三区| 国产欧美精品一区二区色综合 | 91色porny在线视频| 99久久国产综合精品色伊| 在线国产亚洲欧美| 日韩午夜在线观看| 丝袜美腿亚洲一区二区图片| 美女爽到高潮91| 国产成人激情av| 一本一本久久a久久精品综合麻豆| 欧美在线观看一区| 欧美一区二区三区不卡| 国产亚洲精久久久久久| 亚洲男同性视频| 日韩成人精品在线观看| 国产在线精品国自产拍免费| 99久久综合精品| 欧美精品v国产精品v日韩精品 | 欧美精品三级日韩久久| 欧美成人乱码一区二区三区| 国产精品三级久久久久三级| 亚洲电影中文字幕在线观看| 国产乱码精品一区二区三区五月婷| 不卡电影一区二区三区| 5月丁香婷婷综合| 国产日韩欧美麻豆| 五月天亚洲婷婷| 丁香五精品蜜臀久久久久99网站 | 在线观看成人小视频| 欧美精品一区视频| 亚洲女同一区二区| 看片的网站亚洲| 色一情一乱一乱一91av| 精品久久国产97色综合| 亚洲午夜在线电影| 国产传媒久久文化传媒| 欧美日韩美少妇| 中文字幕亚洲在| 久久精品国产免费| 精品视频一区二区不卡| 国产精品免费aⅴ片在线观看| 婷婷六月综合亚洲| 97精品国产97久久久久久久久久久久| 日韩欧美综合一区| 午夜精品在线视频一区| 99久久99久久精品免费观看| 欧美tk—视频vk| 亚洲国产成人精品视频| eeuss鲁片一区二区三区| 精品久久国产字幕高潮| 奇米一区二区三区av| 91国产丝袜在线播放| 亚洲国产精品成人综合| 激情久久五月天| 日韩一区二区麻豆国产| 午夜精品一区二区三区三上悠亚| www.亚洲国产| 日本一区二区三区高清不卡| 国产麻豆午夜三级精品| 日韩视频在线观看一区二区| 婷婷夜色潮精品综合在线| 91福利区一区二区三区| 亚洲精品乱码久久久久久久久 | 91精品国产免费久久综合| 亚洲国产精品影院| 91香蕉视频黄| 亚洲欧洲av色图| 成人免费视频免费观看| 国产欧美综合在线观看第十页| 极品少妇xxxx精品少妇偷拍| 日韩视频一区二区| 蜜桃一区二区三区在线观看| 在线综合视频播放| 肉色丝袜一区二区| 在线不卡中文字幕播放| 午夜视频在线观看一区二区 | 国产999精品久久| 亚洲福利一二三区| 欧美日韩国产一级片| 精品黑人一区二区三区久久| 天天影视色香欲综合网老头| 欧美亚一区二区| 亚洲国产日韩av| 欧美片网站yy| 免播放器亚洲一区| 欧美sm美女调教| 国产精品综合在线视频| 亚洲国产精品成人综合| 91丨九色丨国产丨porny| 亚洲免费在线看| 91黄色激情网站| 天天色天天爱天天射综合| 欧美一区二区免费视频| 久久成人免费电影| 国产人伦精品一区二区| av一区二区久久| 亚洲网友自拍偷拍| 91精品国产综合久久香蕉麻豆| 麻豆一区二区三区| 国产三级欧美三级| av中文字幕在线不卡| 亚洲成人综合在线| 日韩视频在线你懂得| 粉嫩嫩av羞羞动漫久久久| 亚洲欧美日韩久久| 91精品国产综合久久精品app| 紧缚奴在线一区二区三区| 国产精品国产自产拍高清av王其| 色播五月激情综合网| 日本成人中文字幕| 欧美国产欧美综合| 色综合久久久久综合体桃花网| 亚洲妇熟xx妇色黄| 久久你懂得1024| 日本精品裸体写真集在线观看| 日韩一区精品字幕| 国产视频一区二区在线| 欧洲另类一二三四区| 美女视频免费一区| 亚洲精品国产成人久久av盗摄| 欧美一卡2卡三卡4卡5免费| 国产a区久久久| 亚洲v日本v欧美v久久精品| 国产亚洲欧美色| 欧美综合在线视频| 国产精品羞羞答答xxdd| 亚洲国产精品一区二区久久恐怖片 | 五月天丁香久久| 国产亚洲一区二区三区| 欧美色欧美亚洲另类二区| 国产一区二区视频在线| 亚洲一区av在线| 国产欧美精品一区aⅴ影院| 欧美夫妻性生活| 91女人视频在线观看| 久久国产精品色| 韩国午夜理伦三级不卡影院| 一区二区三区在线观看国产| 久久久久久亚洲综合影院红桃| 欧美视频在线播放| 成人97人人超碰人人99| 久久成人免费网| 肉色丝袜一区二区|