通过代码:
#include <bits/stdc++.h> using namespace std; char c[1001], k[1001], m[1001]; int code[30][30]; char patch(char _a,char _b) { char _s; if(_b >= 'a' && _b <= 'z') _s = 'a' - 1; else _s = 'A' - 1; for(int i = 1; i <= 26; i ++) if(code[i][tolower(_a) - 'a' + 1] == tolower(_b) - 'a' + 1) return (char)(i + _s); } int main() { for(int i = 1; i <= 26; i ++) for(int j = 1; j <= 26; j ++) code[i][j] = (j + i - 2) % 26 + 1; gets(k); gets(c); int j = 0; for(int i = 0; i < strlen(c); i ++) { m[i] = patch(k[j], c[i]), j ++; if(j == strlen(k)) j = 0; } puts(m); return 0; }
1402:Vigenère密码
最新推荐文章于 2024-04-10 14:02:47 发布