#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 )
}
#include <stdio.h>#include <string.h>
int main()
{
int i = 0
int len = 0
char ch
char buf[256] = {0}
char nor[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
char enc[26] = {'s','u','w','y','a','c','e','g','i','k','m','o','q','r','t','v','x','z','b','d','f','h','j','l','n','p'}
printf("Encode or Decode: ")
scanf("%c",&ch)
printf("please input your string: ")
fflush(stdin)
gets(buf)
len = strlen(buf)
switch (ch)
{
case 'e':
case 'E':
for (i=0i<leni++)
{
buf[i] = enc[buf[i] - 'a']
}
break
case 'd':
case 'D':
for (i=0i<leni++)
{
buf[i] = nor[i]
}
break
default:
printf("wrong input!\n")
}
printf("<%s>\n",buf)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)