本文实例讲述了字符串加密解密c++ ,分享给大家,供大家参考。具体分析如下:
#include <iostream> char* enciphering(char *ch,int &key){ char *str=new char[100]; int i=0,x; bool decide=true; while(ch[i]) { if(ch[i]>='a'&&ch[i]<='z') { x=ch[i]+i+key+1; while(decide) { if(x>'z') x-=26; else decide=false; } decide=true; str[i]=x; } else str[i]=ch[i]; i++; } return str;} { char *str=new char[100]; int i=0,x; bool decide=true; while(ch[i]) { if(ch[i]>='a'&&ch[i]<='z') { x=ch[i]-i-1-key; while(decide) { if(x<'a') x+=26; else decide=false; } decide=true; str[i]=x; } elsestr[i]=ch[i]; i++; } return str;}int main(){ int key,count; char *str=new char[100]; Go: cout<<"1.加密字符串/n2.解密字符串/n3.退出程序"<<endl; cout<<"请选择行为:"; cin>>count; switch(count) { case 1: cout<<"输入要加密的字符串:"; cin.get(); cin.getline(str,100); cout<<"输入密钥:"; cin>>key; str=enciphering(str,key); cout<<"加密后的字符串:"<<str<<endl; break; case 2: cout<<"输入要解密的字符串:"; cin.get(); cin.getline(str,100); cout<<"输入密钥:"; cin>>key; str=deciphering(str,key); cout<<"解密后的字符串:"<<str<<endl; break; case 3: delete [] str; return 0; default: cout<<"没有这个选项,请重新选择!"<<endl; goto go; }goto go;} |
上面只是浅析介绍了字符串加密解密c++ 的内容,仅供大家参考。喜欢的可以继续浏览下页。
延伸阅读:联系客服