® 运算忽略参与运算的字母的大小写,并保持字母在明文 MM 中的大小写形式;
当明文 MM 的长度大于密钥 kk 的长度时,将密钥 kk 重复使用。 例如,明文 M=M=Helloworld,密钥 k=k=abc时,密文 C=C=Hfnlpyosnd。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string k,c;
char ans;
int tip=0,t,f,a[150];
int main()
{
ios::sync_with_stdio(false);
cin>>k>>c;
for(int i=0;i<k.length();i++)
{
if(k[i]>='a'&&k[i]<='z') a[i]=k[i]-'a';
else a[i]=k[i]-'A';
}
for(int i=0;i<c.length();i++)
{
if(c[i]>='a'&&c[i]<='z') f=0,t=c[i]-'a';
else f=1,t=c[i]-'A';
t-=a[tip];
if(t<0) t+=26;
if(f) ans='A'+t;
else ans='a'+t;
cout<<ans;
tip++;
if(tip>=k.length()) tip=0;
}
return 0;
}