⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 des.cpp

📁 DES算法演示
💻 CPP
📖 第 1 页 / 共 3 页
字号:
0x00000010L, 0x00000020L, 0x00000040L, 0x00000080L,
0x00000100L, 0x00000200L, 0x00000400L, 0x00000800L,
0x00001000L, 0x00002000L, 0x00004000L, 0x00008000L,
0x00010000L, 0x00020000L, 0x00040000L, 0x00080000L,
0x00100000L, 0x00200000L, 0x00400000L, 0x00800000L,
0x01000000L, 0x02000000L, 0x04000000L, 0x08000000L,
0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
};

extern unsigned long    key[32];

void des_ec(const void *i_blk, void *o_blk, void *key)
{   unsigned long   q0, q1, l0, l1, tt;

q0 = *(((unsigned long*)i_blk) + 1);
q1 = *(((unsigned long*)i_blk));

ip(q0, q1);

round(q0, q1,  0); round(q1, q0,  2);
round(q0, q1,  4); round(q1, q0,  6);
round(q0, q1,  8); round(q1, q0, 10);
round(q0, q1, 12); round(q1, q0, 14);
round(q0, q1, 16); round(q1, q0, 18);
round(q0, q1, 20); round(q1, q0, 22);
round(q0, q1, 24); round(q1, q0, 26);
round(q0, q1, 28); round(q1, q0, 30);

fp(q1, q0);

*(((unsigned long*)o_blk)) = q0; 
*(((unsigned long*)o_blk) + 1) = q1;
};

void des_ecX(const void *i_blk, void *o_blk, void *key, int index,unsigned long &ll0,unsigned long &ll1)
{   
	unsigned long   q0, q1, l0, l1, tt;

	q0 = *(((unsigned long*)i_blk) + 1);
	q1 = *(((unsigned long*)i_blk));

	ip(q0, q1);
	if(index == 0)
	{
		ll0=q0;
		ll1=q1;
	}




	round(q0, q1,  0);
	if(index == 1)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0,  2);
	if(index == 2)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q0, q1,  4); 
	if(index == 3)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0,  6);
	if(index == 4)
	{
		ll0=q0;
		ll1=q1;
	}


	round(q0, q1,  8);
	if(index == 5)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 10);
	if(index == 6)
	{
		ll0=q0;
		ll1=q1;
	}


	round(q0, q1, 12);
	if(index == 7)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 14);
	if(index == 8)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q0, q1, 16); 
	if(index == 9)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 18);
	if(index == 10)
	{
		ll0=q0;
		ll1=q1;
	}


	round(q0, q1, 20); 
	if(index == 11)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 22);
	if(index == 12)
	{
		ll0=q0;
		ll1=q1;
	}


	round(q0, q1, 24); 
	if(index == 13)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 26);
	if(index == 14)
	{
		ll0=q0;
		ll1=q1;
	}


	round(q0, q1, 28); 
	if(index == 15)
	{
		ll0=q0;
		ll1=q1;
	}

	round(q1, q0, 30);
	if(index == 16)
	{
		ll0=q0;
		ll1=q1;
	}



	fp(q1, q0);
	if(index == 17)
	{
		ll0=q0;
		ll1=q1;
	}


	*(((unsigned long*)o_blk)) = q0; 
	*(((unsigned long*)o_blk) + 1) = q1;
};



void des_dc(const void *i_blk, void *o_blk, void *key)
{   unsigned long   q0, q1, l0, l1, tt;

q0 = *(((unsigned long*)i_blk) + 1); 
q1 = *(((unsigned long*)i_blk));

ip(q0, q1);

round(q0, q1, 30); round(q1, q0, 28);
round(q0, q1, 26); round(q1, q0, 24);
round(q0, q1, 22); round(q1, q0, 20);
round(q0, q1, 18); round(q1, q0, 16);
round(q0, q1, 14); round(q1, q0, 12);
round(q0, q1, 10); round(q1, q0,  8);
round(q0, q1,  6); round(q1, q0,  4);
round(q0, q1,  2); round(q1, q0,  0);

fp(q1, q0);

*(((unsigned long*)o_blk)) = q0; 
*(((unsigned long*)o_blk) + 1) = q1;
};

/* modified encryption routine for DEAL */

void des_ecm(const void *i_blk, void *o_blk, void *key)
{   unsigned long   q0, q1, l0, l1;

q0 = *(((unsigned long*)i_blk) + 1);
q1 = *(((unsigned long*)i_blk));

round(q0, q1,  0); round(q1, q0,  2);
round(q0, q1,  4); round(q1, q0,  6);
round(q0, q1,  8); round(q1, q0, 10);
round(q0, q1, 12); round(q1, q0, 14);
round(q0, q1, 16); round(q1, q0, 18);
round(q0, q1, 20); round(q1, q0, 22);
round(q0, q1, 24); round(q1, q0, 26);
round(q0, q1, 28); round(q1, q0, 30);

*(((unsigned long*)o_blk)) = q0; 
*(((unsigned long*)o_blk) + 1) = q1;
};

//
//	注意!
//
//		如果此 DLL 动态链接到 MFC
//		DLL,从此 DLL 导出并
//		调入 MFC 的任何函数在函数的最前面
//		都必须添加 AFX_MANAGE_STATE 宏。
//
//		例如:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// 此处为普通函数体
//		}
//
//		此宏先于任何 MFC 调用
//		出现在每个函数中十分重要。这意味着
//		它必须作为函数中的第一个语句
//		出现,甚至先于所有对象变量声明,
//		这是因为它们的构造函数可能生成 MFC
//		DLL 调用。
//
//		有关其他详细信息,
//		请参阅 MFC 技术说明 33 和 58。
//

// CDESApp

BEGIN_MESSAGE_MAP(CDESApp, CWinApp)
END_MESSAGE_MAP()


// CDESApp 构造

CDESApp::CDESApp()
{
	// TODO: 在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}


// 唯一的一个 CDESApp 对象

CDESApp theApp;


// CDESApp 初始化

BOOL CDESApp::InitInstance()
{
	CWinApp::InitInstance();

	return TRUE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -