映射表加密程序(替换密码)

来源:百度知道 编辑:UC知道 时间:2024/05/28 23:37:59
一个文本串可用事先给定的字母映射表进行加密。例如,设字母映射表为:
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
q w e r t y u i o p a s d f g h j k l z x c v b n m
则字符串”encrypt”被加密为”tfeknhz”,试写一个算法将输入的已加密的文本串进行解密后输出。
1.Encrypt(SqString p):加密过程
2.Main():用A和B两个字符串存放字母映射表。调用Encrypt()用于加密,即扫描p串,对于当前字母p.ch[i],若在A串中找到的是A.ch[j],则将它转换成B.ch[j],否则保护原字符不变。
谢谢!!!!

有单表替换加密解密c语言程序希望对你能有所帮助
#include<stdio.h>
char a[100];
char d[]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
void encryption();
void decryption();
void encryption()
{int i,j;
char b[100];
printf("please input a plaintext:\n");
gets(b);
printf("the ciphertext is:\n");
for(i=0;i<100;i++)
{if(b[i]==' ')
printf("%c",b[i]);
else if(b[i]!='\0')
{for(j=0;j<53;j++)
{if(d[j]==b[i])
printf("%c",a[j]);
}
}
else
break;}
printf("\n");
}
void decryption()
{char c[100];
int i,j,k;
printf("please input the ciphertext:\n");
gets(c);
printf("the plaintext is:\n");
for(i=0;i<100;i++)
{if(c[i]==' ')
printf("%c",c[i]);
else if(c[i]!='\0