📄 vigenere密码算法.cpp
字号:
#include<iostream>
#include<math.h>
using namespace std;
const int M=30;
int m=0,n=0;
char p[M];
char k[M];
char c[M];
//input the key and plaintext
int main(){
cout<<"Please input the plaintext(end with #):"<<endl;
int i=0;
cin>>p[i];
for(i=1;i<M&&p[i-1]!='#';i++){
m++;
cin>>p[i];}
cout<<"Please input the key(end with #):"<<endl;
i=0;
cin>>k[i];
for(i=1;i<M&&k[i-1]!='#';i++){
n++;
cin>>k[i];}
for(int i=0,j=0;i<m;i++,j++){
if(p[i]==' '){
i++;
m--;
continue;}
else{
if(p[i]>='A'&&p[i]<='Z'){
if(k[j]!='#')
c[i]=(p[i]-'A'+k[j]-'A')%26+65;
else{
j=0;
c[i]=(p[i]-'A'+k[j]-'A')%26+65;}
}
else if(p[i]>='a'&&p[i]<='z'){
if(k[j]!='#')
c[i]=(p[i]-'a'+k[j]-'a')%26+'a';
else{
j=0;
c[i]=(p[i]-'a'+k[j]-'a')%26+'a';}
}
else
cout<<"invalid input!"<<endl;
cout<<c[i];}}
cout<<endl;
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -