用C语言编程恺撒密码加密解密程序
的有关信息介绍如下:
#include #define isletter( c ) ( ((c)>='a'&&(c)<='z') || ((c)>='A'&&(c)<='Z') )void Enc( const char *str, char *out, int key ){ int i = 0; while( str[i] ) { if ( isletter( str[i] ) ) { out[i] = str[i] + key; if ( ! isletter( out[i]) ) out[i] -= 26; } else out[i] = str[i]; i++; } out[i] = 0;}void Denc( const char *str, char *out, int key ){ int i=0; while( str[i] ) { if ( isletter( str[i] ) ) { out[i] = str[i] - key; if ( ! isletter( out[i] ) ) out[i] += 26; } else out[i] = str[i]; i++; } out[i] = 0;}int main(){ char out[100], out2[100]; Enc( "THE QUICK BROWn fox jumps over THE LAZY DOG", out, 3 ); printf( "%s\n", out ); Denc( out, out2, 3 ); printf( "%s\n", out2 );}
版权声明:文章由 去问问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.qwenw.com/life/441430.html