#include <stdio.h>
#include <stdlib.h>
typedef struct snode
{
char data;
struct snode *next;
}LiString;
void DispStr(LiString *s)
{
LiString * p = s->next;
while(p!=NULL)
{
printf("%c",p->data);
p = p->next;
}
printf("\n");
}
void jiami(LiString * &s,char cstr[])
{
char a[] = "ngzqtcobmuhelkpdawxfyivrsj";
char b[] = "abcdefghijklmnopqrstuvwxyz";
int i,j;
LiString *r,*p;
s = (LiString *)malloc(sizeof(LiString));
r = s;
for(i=0;cstr[i] != '\0';i++)
{
for(j=0;j<27;j++)
{
if(cstr[i] == b[j])
{
p = (LiString *)malloc(sizeof(LiString));
p->data = a[j];
r->next = p;
r = p;
}
}
}
r->next = NULL;
}
void jiemi(LiString * &s,char cstr[])
{
char a[] = "ngzqtcobmuhelkpdawxfyivrsj";
char b[] = "abcdefghijklmnopqrstuvwxyz";
int i,j;
LiString *r,*p;
s = (LiString *)malloc(sizeof(LiString));
r = s;
for(i=0;cstr[i] != '\0';i++)
{
for(j=0;j<27;j++)
{
if(cstr[i] == a[j])
{
p = (LiString *)malloc(sizeof(LiString));
p->data = b[j];
r->next = p;
r = p;
}
}
}
r->next = NULL;
}
int main()
{
LiString *s;
int chose;
system("color 0a");
printf("**********************\n");
printf("* 请选择加密或者解密 *\n");
printf("* 1加密 2解密 *\n");
printf("**********************\n");
printf("请选择功能:");
scanf("%d",&chose);
if(chose == 1)
{
char a[100];
printf("请输入需要加密的字符串:");
scanf("%s",&a);
jiami(s,a);
printf("加密后的结果为:");
DispStr(s);
}
else if(chose == 2)
{
char a[100];
printf("请输入需要解密的字符串:");
scanf("%s",&a);
jiemi(s,a);
printf("解密后的字符串为:");
DispStr(s);
}
else
{
printf("错误\n");
}
return 0;
}