大神,谁能帮我修改下这段代码
使之实现这样的效果。不会,求大神帮忙。并附上解释,谢谢啦
比如原文为abcdef,偏移量为5,则有abcdef每个字母按字母表向后移动5位(注:z后接a)可得到密文fghijk。如果要对该文件解密:文件内容为fghijk,偏移量为5,则有fghijk每个字母向前移动5位(注a后接z),可得到原文abcdef。代码:#include #include #include #define Maxsize 50 struct node { char data; int flag; struct node *next; }node; main() { int key=0,i=0,j=0,num=0; char chr[Maxsize],*tmp; struct node *p; struct node *head; printf("请输入原文:\n"); gets(chr); tmp=chr; while(*tmp++!='\0') num++; printf("请输入偏移量:\n"); scanf("%d",&key);/*****建立链表****/ head=(struct node *)malloc(sizeof(struct node)); p=head; for(i=0;i<(num-1);i++) { p->data=NULL; p->flag=0; p->next=(struct node *)malloc(sizeof(struct node)); p=p->next; } p->data=NULL; p->flag=0; p->next=head; /****加密实现***/ p=head; for(i=0;i
for(j=1;j<=key;)
{
p=p->next;
if(p->flag==0) j++;
}
p->data=chr[i];
p->flag=1;
}
printf("密文:\n");
for(i=0;i
{
printf("%c",p->data);
p=p->next;
}
getch();
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27204811/viewspace-737584/
,如需转载,请注明出处,否则将追究法律责任。