#include <stdio.h>
#include <string.h>
char plaintext[72];
char ciphertext[72];
int plaincode[72];
int ciphercode[72];
int k;
unsigned long n;
void decrypt()
{
for (int i = 0; i < n; i++) {
if (plaincode[i] == 0)
plaintext[i] = '_';
else if (plaincode[i] == 27)
plaintext[i] = '.';
else
plaintext[i] = plaincode[i] + 'a' - 1;
}
}
void trans()
{
for (int i = 0; i < n; i++) {
int t = k * i % n;
plaincode[t] = (ciphercode[i] + i) % 28;
}
}
void encrypt()
{
for (int i = 0; i < n; i++) {
if (ciphertext[i] == '_')
ciphercode[i] = 0;
else if (ciphertext[i] == '.')
ciphercode[i] = 27;
else
ciphercode[i] = ciphertext[i] - 'a' + 1;
}
}
int main()
{
while (scanf("%d", &k) && k) {
memset(plaincode, 0, sizeof(int) * 72);
memset(ciphercode, 0, sizeof(int) * 72);
memset(plaintext, '\0', sizeof(char) * 72);
memset(ciphertext, '\0', sizeof(char) * 72);
scanf("%s", ciphertext);
n = strlen(ciphertext);
encrypt();
trans();
decrypt();
printf("%s\n", plaintext);
}
return 0;
}
ZOJ1006-Do the Untwist
最新推荐文章于 2019-06-23 21:05:26 发布