维吉尼亚加密

Vigenere(维吉尼亚)加密:

当输入明文,自动生成随机密匙匹配明文中每个字母并移位加密。

#include<stdio.h>
#include<malloc.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
	struct dualnode
	{
		char data;     //elementype表示一种数据类型,可能是int/char等等
	 struct dualnode *next;   //next 指针,用于链表结构指向下一个节点
		struct dualnode *prior;
	};
	typedef struct dualnode dualnode; //重定义struct node类型为node

	void Out(int i,dualnode *head);
	dualnode* Creat(int n);
	int main()
	{
		dualnode* head;
		srand(time(NULL));
		head = Creat(26);
		char str[10] = "";
		int a[10];
		int n = 0;
		do
		{
			scanf("%c",&str[n]);
			a[n] = rand()%100;
			n++;
		}while((n < 10)&&(str[n-1]!='\n'));
		n = 0;
		/*加密输出*/
		while((n < 10)&&(str[n] != '\n'))
		{
			printf("%d->",a[n]);
			Out((int)(str[n]-'a')+a[n],head);
			n++;
		}
		/*解谜输出*/
		printf("\n");
		n = 0;
		while((n < 10)&&(str[n] != '\n'))
		{
			Out((int)(str[n]-'a'),head);
			n++;
		}
		return 0;
	}
	dualnode* Creat(int n)
	{
		dualnode *p = NULL;
		dualnode *head;
		head =(dualnode *)malloc(sizeof(dualnode));
		p = head;
		dualnode *s;
		int i = 0;
		if(0 != n)
		{
			while(i < n)
			{
				s = (dualnode*)malloc(sizeof(dualnode));
				s->data = 'a'+i;
				p->next = s;
				s->prior = p;
				p = s;
				i++;
			}
			s->next = head->next;
			head->next->prior = s;
		}
		free(head);
		return s->next;
	}
void Out(int i,dualnode *head)
{

		while(i)
		{
			head = head->next;
			i--;
		}
		printf("%c",head->data);
}

《维吉尼亚加密》

    原文作者:维吉尼亚加密问题
    原文地址: https://blog.csdn.net/u013239402/article/details/42060215
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞