- vigenere密码
- 2014-11-04 19:38:20 @
看题目又成了考语文了……
5 条评论
-
stealthassassin LV 9 @ 2015-11-04 10:29:36
这题不需要打表的吧,挺水的
ac代码贴上
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
char a[1005],b[1005],c[1005];
int numk[1005];
int keylen,milen;
int main(){
scanf("%s",a);
keylen=strlen(a);
scanf("%s",b);
for (int i=0;i<keylen;i++)
if (a[i]>='a'&&a[i]<='z') numk[i]=a[i]-'a';
else numk[i]=a[i]-'A';
milen=strlen(b);
for (int i=0;i<milen;i++){
int u;
char ch;
if (b[i]>='a'&&b[i]<='z'){
u=b[i]-'a';
ch='a';
}
else{
u=b[i]-'A';
ch='A';
}
if (u>=numk[i%keylen]){
ch=ch+u-numk[i%keylen];
printf("%c",ch);
continue;
}
else{
ch=ch+u+26-numk[i%keylen];
printf("%c",ch);
continue;
}
}
} -
2014-11-05 17:00:35@
-
2014-11-05 07:41:23@
@twd2 来搞图片啊 -.-
-
2014-11-04 20:40:43@
基本图片都是没有的,去网上搜题目吧,这上面的图片基本上都挂掉了
-
2014-11-04 19:51:40@
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cctype>
#include<iostream>
#include<algorithm>
using namespace std;const int kkk[26][26]={
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0},
{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1},
{3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2},
{4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3},
{5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4},
{6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5},
{7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6},
{8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7},
{9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8},
{10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9},
{11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10},
{12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11},
{13,14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12},
{14,15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13},
{15,16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14},
{16,17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{17,18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
{18,19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
{19,20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18},
{20,21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
{21,22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{22,23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21},
{23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22},
{24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23},
{25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}
};string s,mi;
void init()
{
freopen("vigenere.in","r",stdin);
freopen("vigenere.out","w",stdout);string temp;
cin>>s;temp=s;
cin>>mi;
while(s.length()<mi.length()) s+=temp;
//cout<<s<<endl<<mi<<endl;
}char find(char x,char y)
{
bool sign=false;
if(y>='A' && y<='Z') sign=true;
x=tolower(x);y=tolower(y);
char ans;
for(int i=0;i<26;i++)
if(kkk[x-'a'][i]==y-'a') {ans=i+'a';break;}
if(sign) ans=toupper(ans);
return ans;
}void work()
{
for(int i=0;i<mi.length();i++)
cout<<find(s[i],mi[i]);
}int main()
{
init();
work();
return 0;
}
- 1