|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct num
{
struct num* next;
char data;
}stack;
//创建循环链表
stack* creatList()
{
stack* head = (stack*)malloc(sizeof(stack));
stack* s;
s = (stack*)malloc(sizeof(stack));
stack* p = NULL;
p = head;
int i = 0;
while (i <= 26)
{
s = (stack*)malloc(sizeof(stack));
s->data = 'a'+i;
p->next = s;
p = s;
i++;
}
s->next = head->next;
free(head);
return s->next;
}
//依次定位数据位置,根据随机数进行偏移
move(stack* s,int* e,char *ch)
{
int i,j,len;
stack* p ;
p = NULL;
j = i = 0;
len = strlen(ch);
printf("\n加密为:");
while (1)
{
p = s;
if (i >= len)
break;
while (p->data!=ch[i])
{
p = p->next;
}
for (j = 0; j < e[i]; j++)
{
p = p->next;
}
printf("%c", p->data);
i++;
}
printf("\n");
}
int main()
{
stack* s= creatList();
char ch[50];
printf("输入原文: ");
scanf("%s", ch);
int x,i,a[50];
printf("秘钥为:");
for (i = 0; i < strlen(ch); i++)
{
x = rand() % 26;
printf("%d ", x);
a[i] =x ;
}
move(s, a, ch);
return 0;
} |
|