There is a program of simple encryption and decryption ,it pass the compile and build,but stop at the running process.No whether how I input character thought keyboard,it couldn't end with the termination condition,let alone could have any result.any friend can give me a look?thanks!
Code:
#include<stdio.h>
#include<string.h>
#define MaxSize 100
typedef struct
{char ch[MaxSize];
int len;
}SqString;
SqString A,B;
void StrAssign(SqString &str,char cstr[])
{int i;
for(i=0;cstr[i]!='\0';i++)
str.ch[i]=cstr[i];
str.len=i;
}
void DispStr(SqString s)
{int i;
if(s.len>0)
{for(i=0;i<s.len;i++)
printf("%c",s.ch[i]);
printf("\n");}}
SqString EnCrypt(SqString p) /*algorithm of encrypt with simple character*/
/*exchange */
{int i=0,j;
SqString q;
while(i<p.len)
{for(j=0;p.ch[i]!=A.ch[j];j++);
if(j>=A.len)
q.ch[i]=p.ch[i];
else
q.ch[i]=B.ch[j];
i++;
}
q.len=p.len;
return q;
}
SqString UnEncrypt(SqString q) /*reverse of encrypt */
{int i=0,j;
SqString p;
while(i<q.len)
{for(j=0;q.ch[i]!=B.ch[j];j++);
if(j>=B.len)
p.ch[i]=q.ch[i];
else p.ch[i]=A.ch[j];
i++;
}
p.len=q.len;
return p;
}
int main()
{SqString p,q;i
nt i=0,j,k=0,t=0;
char ch;
char s1[MaxSize],s2[MaxSize],s[MaxSize];
do{k1:ch=getchar(); /*initialize s1 without the same character*/
for(j=0;j<i;j++)
if(ch==s1[j]) goto k1;
s1[i++]=ch;
}while(s1[i-1]!='\0');
printf("\n");
while(k<i-1) /*initialize s2 without the same character,and the */
/*length of array s2 should be as the same as array s1*/
{k2:ch=getchar();
for(j=0;j<k;j++)
if(s2[j]==ch) goto k2;
s2[k++]=ch;}
s2[k]='\0';
printf("\n");
do{k3:ch=getchar(); /* initialize s*/
for(j=0;s1[j]!='\0'&&s1[j]!=ch;j++);
if(j>=i-1)
{for(j=0;s2[j]!='\0';j++)
if(ch==s2[j]) goto k3;}
s[k++]=ch;
}while(s[k-1]!='\0');
printf("\n");
StrAssign(A,s1);
StrAssign(B,s2);
StrAssign(p,s);
printf("加密解密如下:\n");
printf("原文串:");
DispStr(p);
q=EnCrypt(p);
printf("加密串:");
DispStr(q);
p=UnEncrypt(q);
printf("解密串:");
DispStr(p);
printf("\n");
return 0;
}