恺撒密码C++代码#includeusing namespace std;//头文件
typedef struct node{int data;node *next;}Node;//定义一个node结构,其结构名为Node
void print(Node *head){Node *p;p=head->next;//定义一个指向输出链表的指针if(p==NULL){cout<<"无";} while(p->next!=NULL){if(p->data==65){cout<<'A';}else if(p->data==66){cout<<'B';}else if(p->data==67){cout<<'C';}else if(p->data==68){cout<<'D';}else if(p->data==69){cout<<'E';}else if(p->data==70){cout<<'F';}else if(p->data==71){cout<<'G';}else if(p->data==72){cout<<'H';}else if(p->data==73){cout<<'I';}else if(p->data==74){cout<<'J';}else if(p->data==75){cout<<'K';}else if(p->data==76){cout<<'L';}else if(p->data==77){cout<<'M';}else if(p->data==78){cout<<'N';}else if(p->data==79){cout<<'O';}else if(p->data==80){cout<<'P';}else if(p->data==81){cout<<'Q';}else if(p->data==82){cout<<'R';}else if(p->data==83){cout<<'S';}else if(p->data==84){cout<<'T';}else if(p->data==85){cout<<'U';}else if(p->data==86){cout<<'V';}else if(p->data==87){cout<<'W';}else if(p->data==88){cout<<'X';}else if(p->data==89){cout<<'Y';}else if(p->data==90){cout<<'Z';}若图片无法显示请联系QQ3710167,恺撒密码C++代码免费,转发请注明源于www.lwfree.cnelse if(p->data==121){cout<<'y';}else if(p->data==122){cout<<'z';} p=p->next; } if(p->data==65){cout<<'A';} else if(p->data==66){cout<<'B';}else if(p->data==67){cout<<'C';}else if(p->data==68){cout<<'D';}else if(p->data==69){cout<<'E';}else if(p->data==70){cout<<'F';}else if(p->data==71){cout<<'G';}else if(p->data==72){cout<<'H';}else if(p->data==73){cout<<'I';}else if(p->data==74){cout<<'J';}else if(p->data==75){cout<<'K';}else if(p->data==76){cout<<'L';}else if(p->data==77){cout<<'M';}else if(p->data==78){cout<<'N';}else if(p->data==79){cout<<'O';}else if(p->data==80){cout<<'P';}else if(p->data==81){cout<<'Q';}else if(p->data==82){cout<<'R';}else if(p->data==83){cout<<'S';}else if(p->data==84){cout<<'T';}else if(p->data==85){cout<<'U';}else if(p->data==86){cout<<'V';}else if(p->data==87){cout<<'W';}else if(p->data==88){cout<<'X';}else if(p->data==89){cout<<'Y';}else if(p->data==90){cout<<'Z';}else if(p->data==97){cout<<'a';}else if(p->data==98){cout<<'b';}else if(p->data==99){cout<<'c';}else if(p->data==100){cout<<'d';}else if(p->data==101){cout<<'e';}else if(p->data==102){cout<<'f';}else if(p->data==103){cout<<'g';}else if(p->data==104){cout<<'h';}else if(p->data==105){cout<<'i';}else if(p->data==106){cout<<'j';}else if(p->data==107){cout<<'k';}else if(p->data==108){cout<<'l';}else if(p->data==109){cout<<'m';}else if(p->data==110){cout<<'n';}else if(p->data==111){cout<<'o';}else if(p->data==112){cout<<'p';}else if(p->data==113){cout<<'q';}else if(p->data==114){cout<<'r';}else if(p->data==115){cout<<'s';}else if(p->data==116){cout<<'t';}else if(p->data==117){cout<<'u';}else if(p->data==118){cout<<'v';}else if(p->data==119){cout<<'w';}else if(p->data==120){cout<<'x';}else if(p->data==121){cout<<'y';}else if(p->data==122){cout<<'z';} cout<next=NULL;m=n;q=head;p=head->next; for(int i=0;idata>='a'&&p->data<='z') {p->data+=key%26; if(p->data>'z'){p->data-=26;} p->data-=32; } q->next=p->next; p->next=NULL; m->next=p; m=p; p=q->next; } cout<<"密文为:"; print(n); jiemi(n,count,key);}
void jiemi(Node *n,int count,int key){void print(Node *);Node *p,*q,*r,*s;//定义结构指针r=(Node *)malloc(sizeof(Node));r->next=NULL;s=r;q=n;p=n->next; for(int i=0;idata-=key%26; if(p->data<'A'){p->data+=26;} p->data+=32; q->next=p->next; p->next=NULL; s->next=p; s=p; p=q->next;} cout<<"解密后原文为:"; print(r);}
//主函数void main(){void print(Node *);//输出函数声明void jiemi(Node *n,int count,int key);void casar(Node *head,int key,int count);Node *head,*p,*q;int key,count=0;char it; head=(Node *)malloc(sizeof(Node));head->next=NULL;q=head;cout<<"请输入明文:";cin>>it;//新建链表算法while(it!='