维吉尼亚密码(完整代码,C++实现)
2021/9/21 1:27:39
本文主要是介绍维吉尼亚密码(完整代码,C++实现),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
长时间不登录,今天一看,哟,居然涨粉了,那就发点东西吧,最近忙,等空下来再认真把把思路逻辑一类的内容整理一下,暂且只发代码,有需要的朋友们可以参考借鉴一下。
//vignere密码 #include<iostream> #include<cstring> using namespace std; //加密 string encrypt(string p,string k) { string c=""; int lk=k.size(),pl=p.size(),s=0; for(int i=0;i<pl;i++) { //其它字符 if(p[i]>='a'&&p[i]<='z') { int j=(i-s)%lk; c+=(p[i]-'a'+k[j]-'a')%26+'a'; } else if(p[i]>='A'&&p[i]<='Z') { int j=(i-s)%lk; c+=(p[i]-'A'+k[j]-'a')%26+'A'; } else { c+=p[i]; s++; } } return c; } //解密 string decrypt(string c,string k) { string p=""; int lk=k.size(),cl=c.size(),s=0; for(int i=0;i<cl;i++) { //其它字符 if(c[i]>='a'&&c[i]<='z') { int j=(i-s)%lk; p+=(c[i]-'a'+26-(k[j]-'a'))%26+'a'; } else if(c[i]>='A'&&c[i]<='Z') { int j=(i-s)%lk; p+=(c[i]-'A'+26-(k[j]-'a'))%26+'a'; } else { p+=c[i]; s++; } } return p; } int main() { string a,b; cout<<"请输入明文(可以输入任意符号,但仅对大小写字母进行加密):"; getline(cin,a); cout<<"请输入密钥:"; getline(cin,b); cout<<"密文为:"<<encrypt(a,b)<<endl; cout<<"明文为:"<<decrypt(encrypt(a,b),b); } //today when people talk about red cross organization, they shake their heads and dont trust this organization. people react for it originated from about four years ago, at that time, a girl showed off her luxury in the public media, she told people that her father was a member of the red cross organization. more and more people knew her, they thought they were cheated by the organization, the money they donated was not used in the right way. the incident has a great negative influence on the red cross organization, people dot trust it any more, they are not willing to donate their money. as for me, i will not donate money to the organization, i choose to give money to the person who is in need of help, so the money wont be taken by others, make sure the person get the real money.
最后一行为提供的可以进行加密的文本。
这篇关于维吉尼亚密码(完整代码,C++实现)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-08测试人员在 Scrum 中的角色是什么?
- 2024-07-07Dify + TiDB Vector,快速构建你的AI Agent
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享