题目大意就是根据字母的序号和给出的公式将密码翻译过来。
#include <stdio.h>
#include <string.h>
int main ( )
{
int ciphercode[ 70 ] , plaincode[ 70 ] ;
char plaintext[ 70 ] , ciphertext[ 70 ] ;
int K ;
while ( scanf("%d",&K ) , K )
{
scanf("%s",ciphertext );
int i , n ;
n = strlen( ciphertext ) ;
for ( i = 0 ; i < n ; i ++ )
{
if ( ciphertext[ i ] == '.' )
ciphercode[ i ] = 27;
if ( ciphertext[ i ] == '_' )
ciphercode[ i ] = 0;
else if ( ciphertext[ i ] >= 'a' && ciphertext[ i ] <= 'z' )
ciphercode[ i ] = ciphertext[ i ] - 'a' + 1 ;
}
for ( i = 0 ; i < n ; i ++ )
plaincode[ ( i*K) % n ] = ( ( ciphercode[ i ] + i ) % 28 ) ;
for ( i = 0 ; i < n ; i ++ )
{
if ( plaincode[ i ] == 27 )
plaintext[ i ] = '.' ;
if ( plaincode[ i ] == 0 )
plaintext[ i ] = '_' ;
else if ( plaincode[ i ] > 0 && plaincode[ i ] < 27 )
plaintext[ i ] = plaincode[ i ] + 'a' - 1 ;
}
for ( i = 0 ; i < n ; i ++ )
printf( "%c", plaintext[ i ] );
printf("\n");
}
return 0;
}
整体思路是很清晰的,在公式的转换那里一直卡壳。。。根据网上的代码改过来了。。。
本文介绍了一个基于特定公式的密码转换算法实现,通过C语言代码详细展示了如何将密文转化为明文的过程,包括特殊字符的处理及按公式进行的位移转换。

371

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



