基于单片机的DES加密解密算法C源码
void rotate_l(uint8_t *key)
{
uint8_t str_x[8];
uint8_t i;
for (i=0; i < 8; ++i) str_x[i] = key[i];
for (i=0; i < 7; ++i)
{
key[i] = (key[i] < 1);
if ((i < 6) && ((str_x[i+1] & 128) == 128))
key[i] |= 1;
}
if (str_x[0] & 0x80 )
key[3] |= 0x10;
else
key[3] &= ~0x10;
if (str_x[3] & 0x08 )
key[6] |= 0x01;
else
key[6] &= ~0x01;
}
/************************************************************************/
/* */
/* Module title: compute_subkeys */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: Computes the 16 sub keys for use in the */
/* DES algorithm */
/* */
/* input parameter 1: pointer to first byte in key string */
/* output : fills the array sub_keys[16][8] with */
/* sub keys and stores the input key in */
/* main_key[8] */
/************************************************************************/
void compute_subkeys(uint8_t *key)
{
uint8_t i, j, ikey[8], okey[8];
for (i=0; i < 8; ++i)
{
main_key[i] = key[i];
}
transpose(key, ikey, key_tr1, 56);
for (i=0; i < 16; ++i)
{
for (j=0; j < rots[i]; ++j) {rotate_l(ikey);}
transpose(ikey, okey, key_tr2, 64);
for (j=0; j < 8; ++j)
{sub_keys[i][j] = okey[j];}
}
}
/************************************************************************/
/* */
/* Module title: f */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: The chipher function */
/* */
/* input parameter 1: pointer to first byte in key string */
/* 2: pointer to a 32 bit input string */
/* 3: pointer to a 32 bit output string */
/************************************************************************/
void f(uint8_t *skey, uint8_t *a_str, uint8_t *x_str)
{
uint8_t e_str[8], y_str[8], z_str[8];
uint8_t k;
transpose(a_str, e_str, etr, 64);
for (k=0; k < 8; ++k)
{
y_str[k] = (e_str[k] ^ skey[k]) & 63;
z_str[k] = s[k] [y_str[k]];
}
transpose(z_str, x_str, ptr, 32);
}
//源码完毕
单片机DES加密解密算 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)