这学期开始学习密码学,无意中发现实验室里的一本数论书有密码学的专题,然后就开始对着刷,希望能让自己的数论和密码学更上一层楼
思路:这题自然是超级无敌大水题,密码学里称 c = a * m + b (mod q) 为仿射密码,gcd(a, q) == 1;当a == 1时,c = m + b (mod q) 为加法密码,此时若b == 3,则为凯撒密码;当b == 0时,c = a * m (mod q) 为密码
题目链接:http://poj.org/problem?id=3749
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
char s[1000];
int main()
{
while (gets(s))
{
if (strcmp(s, "ENDOFINPUT") == 0) break;
gets(s);
for (int i = 0; s[i]; i++)
if (isalpha(s[i]))
s[i] = (s[i] - 'A' - 5 + 26) % 26 + 'A';
puts(s);
gets(s);
}
return 0;
}