ZOJ Problem Set - 1006
Do the Untwist
#include<stdio.h>
#include<string.h>
char mid[] = "_abcdefghijklmnopqrstuvwxyz.";
char ciphertext[75] ={ 0 };
char plaintext[75] = { 0 };
int ciphercode[75] = { 0 };
int plaincode[75] = { 0 };
int main(void)
{
int k, n, i, j;
while (scanf("%d", &k) == 1 && k)
{
scanf("%s", ciphertext);
n = strlen(ciphertext);
for (i = 0; i < n; ++i)
for ( j = 0; j < 28; ++j)
if (ciphertext[i] == mid[j])
{ ciphercode[i] = j; break; }
for (i = 0; i < n; ++i)
plaincode[k*i%n] = (ciphercode[i] + i) % 28;
for (i = 0; i < n; ++i)
plaintext[i] = mid[plaincode[i]];
plaintext[i] = '\0';
puts(plaintext);
}
return 0;
}
本文介绍了一个名为DotheUntwist的算法实现,该算法通过一系列字符转换过程来解码特定形式的密文。文章展示了如何使用C语言进行编码,并详细解释了字符映射、密文解析及还原明文的过程。


被折叠的 条评论
为什么被折叠?



