Vigenère 密码
这个东西的源码:
```html
可登录,可提交,挺好使
```
注:动态题面查看测试中,有问题反馈哦。
标签:
\(\fbox{模拟}\)
\(\fbox{字符串处理}\)
代码:
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;
char s[28][28] = {
{"abcdefghijklmnopqrstuvwxyz"},
{"bcdefghijklmnopqrstuvwxyza"},
{"cdefghijklmnopqrstuvwxyzab"},
{"defghijklmnopqrstuvwxyzabc"},
{"efghijklmnopqrstuvwxyzabcd"},
{"fghijklmnopqrstuvwxyzabcde"},
{"ghijklmnopqrstuvwxyzabcdef"},
{"hijklmnopqrstuvwxyzabcdefg"},
{"ijklmnopqrstuvwxyzabcdefgh"},
{"jklmnopqrstuvwxyzabcdefghi"},
{"klmnopqrstuvwxyzabcdefghij"},
{"lmnopqrstuvwxyzabcdefghijk"},
{"mnopqrstuvwxyzabcdefghijkl"},
{"nopqrstuvwxyzabcdefghijklm"},
{"opqrstuvwxyzabcdefghijklmn"},
{"pqrstuvwxyzabcdefghijklmno"},
{"qrstuvwxyzabcdefghijklmnop"},
{"rstuvwxyzabcdefghijklmnopq"},
{"stuvwxyzabcdefghijklmnopqr"},
{"tuvwxyzabcdefghijklmnopqrs"},
{"uvwxyzabcdefghijklmnopqrst"},
{"vwxyzabcdefghijklmnopqrstu"},
{"wxyzabcdefghijklmnopqrstuv"},
{"xyzabcdefghijklmnopqrstuvw"},
{"yzabcdefghijklmnopqrstuvwx"},
{"zabcdefghijklmnopqrstuvwxy"},
};
signed main() {
string key;
string v1;
char v2[1000101];
int v2len = 0;
memset(v2,' ',sizeof(v2));
cin>>key;
cin>>v1;
if(v1.length()>key.length()) {
int i = 0;
int j = 0;
int k = 0;
while(j<v1.length()) {
//´¦Àí´óд
if(v1[j]>='A'&&v1[j]<='Z') {
if(key[i]>='A'&&key[i]<='Z') {
key[i] = key[i]-'A'+'a';
}
for(k = 0;k<26;++k) {
if(s[k][key[i]-'a']==v1[j]-'A'+'a') {
v2[v2len] = k+'A';
v2len++;
}
}
}
//´¦ÀíСд
if(v1[j]>='a'&&v1[j]<='z') {
if(key[i]>='A'&&key[i]<='Z') {
key[i] = key[i]-'A'+'a';
}
for(k = 0;k<26;++k) {
if(s[k][key[i]-'a']==v1[j]) {
v2[v2len] = k+'a';
v2len++;
}
}
}
i++;
j++;
if(i==key.length()) {
i = 0;
}
}
} else {
int i = 0;
int j = 0;
int k = 0;
while(j<v1.length()) {
//´¦Àí´óд
if(v1[j]>='A'&&v1[j]<='Z') {
if(key[i]>='A'&&key[i]<='Z') {
key[i] = key[i]-'A'+'a';
}
for(k = 0;k<26;++k) {
if(s[k][key[i]-'a']==v1[j]-'A'+'a') {
v2[v2len] = k+'A';
v2len++;
}
}
}
//´¦ÀíСд
if(v1[j]>='a'&&v1[j]<='z') {
if(key[i]>='A'&&key[i]<='Z') {
key[i] = key[i]-'A'+'a';
}
for(k = 0;k<26;++k) {
if(s[k][key[i]-'a']==v1[j]) {
v2[v2len] = k+'a';
v2len++;
}
}
}
i++;
j++;
}
}
// cout<<v2len<<endl;
for(int i = 0;i<v2len;++i) {
cout<<v2[i];
}
}
Copyright littlefrog(2019)
所有权利保留。