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

📄 des.c

📁 DES算法演示
💻 C
📖 第 1 页 / 共 3 页
字号:

    0x08200020L, 0x08208000L, 0x00008020L, 0x00000000L,
    0x08008000L, 0x00200020L, 0x08200000L, 0x08208020L,
    0x00000020L, 0x08000000L, 0x00208000L, 0x00008020L,
    0x00208020L, 0x08008020L, 0x08000020L, 0x08200000L,
    0x00008000L, 0x00208020L, 0x00200020L, 0x08008000L,
    0x08208020L, 0x08000020L, 0x00000000L, 0x00208000L,
    0x08000000L, 0x00200000L, 0x08008020L, 0x08200020L,
    0x00200000L, 0x00008000L, 0x08208000L, 0x00000020L,
    0x00200000L, 0x00008000L, 0x08000020L, 0x08208020L,
    0x00008020L, 0x08000000L, 0x00000000L, 0x00208000L,
    0x08200020L, 0x08008020L, 0x08008000L, 0x00200020L,
    0x08208000L, 0x00000020L, 0x00200020L, 0x08008000L,
    0x08208020L, 0x00200000L, 0x08200000L, 0x08000020L,
    0x00208000L, 0x00008020L, 0x08008020L, 0x08200000L,
    0x00000020L, 0x08208000L, 0x00208020L, 0x00000000L,
    0x08000000L, 0x08200020L, 0x00008000L, 0x00208020L,

    0x08200020L, 0x08208000L, 0x00008020L, 0x00000000L,
    0x08008000L, 0x00200020L, 0x08200000L, 0x08208020L,
    0x00000020L, 0x08000000L, 0x00208000L, 0x00008020L,
    0x00208020L, 0x08008020L, 0x08000020L, 0x08200000L,
    0x00008000L, 0x00208020L, 0x00200020L, 0x08008000L,
    0x08208020L, 0x08000020L, 0x00000000L, 0x00208000L,
    0x08000000L, 0x00200000L, 0x08008020L, 0x08200020L,
    0x00200000L, 0x00008000L, 0x08208000L, 0x00000020L,
    0x00200000L, 0x00008000L, 0x08000020L, 0x08208020L,
    0x00008020L, 0x08000000L, 0x00000000L, 0x00208000L,
    0x08200020L, 0x08008020L, 0x08008000L, 0x00200020L,
    0x08208000L, 0x00000020L, 0x00200020L, 0x08008000L,
    0x08208020L, 0x00200000L, 0x08200000L, 0x08000020L,
    0x00208000L, 0x00008020L, 0x08008020L, 0x08200000L,
    0x00000020L, 0x08208000L, 0x00208020L, 0x00000000L,
    0x08000000L, 0x08200020L, 0x00008000L, 0x00208020L,
#endif
  }
};

unsigned long bs_tab[] =
{   0x00000001L, 0x00000002L, 0x00000004L, 0x00000008L,
    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;
};

⌨️ 快捷键说明

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