在密码学中,恺撒密码(英语:Caesar cipher),或称恺撒加密、恺撒变换、变换加密,是一种最简单且最广为人知的加密技术。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推。这个加密方法是以罗马共和时期恺撒的名字命名的,当年恺撒曾用此方法与其将军们进行联系。—— 摘自百度百科《凯撒密码》
#include <stdio.h>
#include <stdlib.h>
typedef struct duonode {
char data ;
struct duonode *prior ;
struct duonode *next ;
} duonode ;
duonode *createduolist (duonode *head)
{
head = (duonode *)malloc(sizeof(duonode));
head->next = head->prior = NULL ;
duonode *tmp = head ;
duonode *add = NULL ;
for (int i = 0 ; i < 26 ; i++)
{
add = (duonode *)malloc(sizeof(duonode));
add->next = tmp->next ; // 安排好待插入结点的next指针域
add->prior = tmp ; // 安排好其prior指针域
add->data = 'A' + i ;
tmp->next = add ; // 安排好上一个结点的next指针域
tmp = add ; // 迁移tmp的位置
}
tmp->next = head->next ;
head->next->prior = tmp ;
free(head);
return tmp->next ;
}
duonode *caser (duonode *head , int num)
{
duonode *tmp = head ;
if (num > 0)
{
while (num > 0)
{
tmp = tmp->next ;
num-- ;
}
}
else
{
while (num < 0)
{
tmp = tmp->prior ;
num++ ;
}
}
return tmp ;
}
int main ()
{
int input ;
duonode *head = NULL ;
head = createduolist (head);
scanf("%d",&input);
head = caser(head , input);
duonode *tmp = head ;
for (int i = 0 ; i < 26 ; i++)
{
printf("%c ",tmp->data);
tmp = tmp->next ;
}
}