C语言设计一个简单的加密解密程序如下:
企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,成都创新互联面向各种领域:成都主动防护网等成都网站设计公司、全网整合营销推广解决方案、网站设计等建站排名服务。
加密程序代码:
#includestdio.h
main()
{
char
c,filename[20];
FILE
*fp1,*fp2;
printf("请输入待加密的文件名:\n");
scanf("%s",filename);
fp1=fopen(filename,"r");
fp2=fopen("miwen.txt","w");
do
{
c=fgetc(fp1);
if(c=32c=126)
{
c=c-32;
c=126-c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
解密程序代码:
#includestdio.h
#includestring.h
main()
{
char
c,filename[20];
char
yanzhengma[20];
FILE
*fp1,*fp2;
printf("请输入待解密文件名:\n");
scanf("%s",filename);
printf("请输入验证码:\n");
scanf("%s",yanzhengma);
if(strcmp(yanzhengma,"shan")==0)
{
fp1=fopen(filename,"r");
fp2=fopen("yuanwen.txt","w");
do
{
c=fgetc(fp1);
if(c=32c=126)
{
c=126-c;
c=32+c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
else
{
printf("验证码错误!请重新输入:\n");
scanf("%s",filename);
}
}
C语言代码和运行结果如下:
输出符合示例,加解密均正确,望采纳~
附源码链接:字符串加解密
#include stdio.h
#include stdlib.h
#include string.h
const char *chlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int encode_string(char* str, unsigned int length, char* stat) {
char s[103];
int i,j;
unsigned temp;
if(length = 0) return 1;
if(length 100) return 2;
str[length] = '\0';
strcpy(s,str);
while(strlen(s) % 3) strcat(s,"=");
for(i = 0,j = 0; s[i]; i += 3,j += 4) {
temp = s[i];
temp = (temp 8) + s[i + 1];
temp = (temp 8) + s[i + 2];
stat[j + 3] = chlist[temp 0X3F];
temp = 6;
stat[j + 2] = chlist[temp 0X3F];
temp = 6;
stat[j + 1] = chlist[temp 0X3F];
temp = 6;
stat[j + 0] = chlist[temp 0X3F];
}
stat[j] = '\0';
return 0;
}
int Index(char ch) {
int i;
for(i = 0; chlist[i]; ++i) {
if(chlist[i] == ch)
return i;
}
return -1;
}
void decode_string(char *s, char *t) {
unsigned temp;
int i,j,k,len = strlen(s);
if(len % 4) {
printf("无效数据。\n");
exit(2);
}
for(i = 0,j = 0; i = len; i += 4,j += 3) {
temp = 0;
for(k = 0; k 4; ++k)
temp = (temp 6) + Index(s[i + k]);
for(k = 2; k = 0; --k) {
t[j + k] = temp 0XFF;
temp = 8;
}
}
t[j + k] = '\0';
}
int main() {
char s[100] = "1a2a3s4dff5fj6u7M8B9P0O1U2";
char t[150],u[100];
printf("s = %s\n",s);
encode_string(s,strlen(s),t);
printf("t = %s\n",t);
decode_string(t,u);
printf("u = %s\n",u);
return 0;
}
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款