标签:cout ++ else cpp using put bit ble names
定义:戳这里
加密:
#include<bits/stdc++.h>
using namespace std;
char a[1200],b[1200],tmp,ans[1200];
int main()
{
printf(" Vigenère加密\n\n" );
printf("输入秘钥:");scanf("%s",b);puts("");
printf("输入明文:");scanf("%s",a);puts("");
for(int i=0;i<strlen(a);)
{
for(int j=0;j<strlen(a)&&j<strlen(b);j++,i++)
{
int tmp;
if(b[j]>='A'&&b[j]<='Z')tmp=b[j]-'A'+'a';
else tmp=b[j];
tmp=tmp-'a';
if(a[i]>='a'&&a[i]<='z') {
if(tmp+a[i]>'z')ans[i]=tmp-26+a[i];
else ans[i]=tmp+a[i];
}
if(a[i]>='A'&&a[i]<='Z') {
if(tmp+a[i]>'Z')ans[i]=tmp-26+a[i];
else ans[i]=tmp+a[i];
}
}
}
printf("密文:%s\n",ans);
return 0;
}
解密:
#include<bits/stdc++.h>
using namespace std;
char a[1200],b[1200],tmp,ans[1200];
int main()
{
cout<<" Vigenère解密\n" <<endl;
cout<<"输入秘钥:";scanf("%s",b);puts("");
cout<<"输入秘文:";scanf("%s",a);puts("");
for(int i=0;i<strlen(a);)
{
for(int j=0;j<strlen(a)&&j<strlen(b);j++,i++)
{
if(a[i]>='A'&&a[i]<='Z')
{
if(b[j]>='a'&&b[j]<'z')tmp=b[j]-'a'+'A';
else tmp=b[j];
if(a[i]-tmp>=0)ans[i]=a[i]-tmp+'A';
else ans[i]=a[i]-tmp+'Z'+1;
}
if(a[i]>='a'&&a[i]<='z')
{
if(b[j]>='A'&&b[j]<='Z')tmp=b[j]-'A'+'a';
else tmp=b[j];
if(a[i]-tmp>=0)ans[i]=a[i]-tmp+'a';
else ans[i]=a[i]-tmp+'z'+1;
}
}
}
printf("明文:%s\n",ans);
return 0;
}
标签:cout ++ else cpp using put bit ble names
原文地址:https://www.cnblogs.com/zzctommy/p/12410107.html