| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3866 人关注过本帖
标题:谁可以用c++实现des算法呀
只看楼主 加入收藏
海星两元
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-12-16
收藏
得分:0 

太长了,发不了,接上面.........
int uufwriteEnd(fp)
FILE *fp;
{
int j;
static char *end=" \nend\n";

if (uubufnum != 0)
{
uubuf[uubufnum]='\0';
uubuf[uubufnum+1]='\0';
uubuf[uubufnum+2]='\0';
j=uuencode(uubuf,uubufnum,b);
fwrite(b,1,j,fp);
}
fwrite(end,1,strlen(end),fp);
}

int uufread(out,size,num,fp)
char *out;
int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
int num;
FILE *fp;
{
int i,j,tot;
static int done=0;
static int valid=0;
static int start=1;

if (start)
{
for (;;)
{
b[0]='\0';
fgets(b,300,fp);
if (b[0] == '\0')
{
fprintf(stderr,"no 'begin' found in uuencoded input\n");
return(-1);
}
if (strncmp(b,"begin ",6) == 0) break;
}
start=0;
}
if (done) return(0);
tot=0;
if (valid)
{
bcopy(bb,out,valid);
tot=valid;
valid=0;
}
for (;;)
{
b[0]='\0';
fgets(b,300,fp);
if (b[0] == '\0') break;
i=strlen(b);
if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
{
done=1;
while (!feof(fp))
{
fgets(b,300,fp);
}
break;
}
i=uudecode(b,i,bb);
if (i < 0) break;
if ((i+tot+8) > num)
{
/* num to copy to make it a multiple of 8 */
j=(num/8*8)-tot-8;
bcopy(bb,&(out[tot]),j);
tot+=j;
bcopy(&(bb[j]),bb,i-j);
valid=i-j;
break;
}
bcopy(bb,&(out[tot]),i);
tot+=i;
}
return(tot);
}

#define ccc2l(c,l) (l =((unsigned long)(*((c)++)))<<16, \
l|=((unsigned long)(*((c)++)))<< 8, \
l|=((unsigned long)(*((c)++))))

#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff))


int uuencode(in,num,out)
unsigned char *in;
int num;
unsigned char *out;
{
int j,i,k,n,tot=0;
unsigned long l;
register unsigned char *p;
p=out;

for (j=0; j<num; j+=45)
{
if (j+45 > num)
i=(num-j);
else i=45;
*(p++)=i+' ';
for (n=0; n<i; n+=3)
{
ccc2l(in,l);
*(p++)=((l>>18)&0x3f)+' ';
*(p++)=((l>>12)&0x3f)+' ';
*(p++)=((l>> 6)&0x3f)+' ';
*(p++)=((l )&0x3f)+' ';
tot+=4;
}
*(p++)='\n';
tot+=2;
}
*p='\0';
l=0;
return(tot);
}

int uudecode(in,num,out)
unsigned char *in;
int num;
unsigned char *out;
{
int j,i,k;
unsigned int n,space=0;
unsigned long l;
unsigned long w,x,y,z;
unsigned int blank='\n'-' ';

for (j=0; j<num; )
{
n= *(in++)-' ';
if (n == blank)
{
n=0;
in--;
}
if (n > 60)
{
fprintf(stderr,"uuencoded line length too long\n");
return(-1);
}
j++;

for (i=0; i<n; j+=4,i+=3)
{
/* the following is for cases where spaces are
* removed from lines.
*/
if (space)
{
w=x=y=z=0;
}
else
{
w= *(in++)-' ';
x= *(in++)-' ';
y= *(in++)-' ';
z= *(in++)-' ';
}
if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
{
k=0;
if (w == blank) k=1;
if (x == blank) k=2;
if (y == blank) k=3;
if (z == blank) k=4;
space=1;
switch (k) {
case 1: w=0; in--;
case 2: x=0; in--;
case 3: y=0; in--;
case 4: z=0; in--;
break;
case 0:
space=0;
fprintf(stderr,"bad uuencoded data values\n");
w=x=y=z=0;
return(-1);
break;
}
}
l=(w<<18)|(x<<12)|(y<< 6)|(z );
l2ccc(l,out);
}
if (*(in++) != '\n')
{
fprintf(stderr,"missing nl in uuencoded line\n");
w=x=y=z=0;
return(-1);
}
j++;
}
*out='\0';
w=x=y=z=0;
return(n);
}

2005-12-19 14:45
realism
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-12-21
收藏
得分:0 

我有一份。
我邮箱fengsha_cj@126.com
我现在在机房,考不上来。
回到宿舍才有

[此贴子已经被作者于2005-12-21 15:20:32编辑过]

2005-12-21 15:20
快速回复:谁可以用c++实现des算法呀
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018712 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved