#include <stdio.h>
#include <stdlib.h>
#define KEY 11 //偏移量
int encrypt(char password[])//加密
{
int i=0;
int count = strlen(password);
for(;i<count;i++)
{
password[i]=password[i]+i+KEY;
}
return password;
}
int dencrypt(char password[])//解密
{
int i=0;
int count = strlen(password);
for(;i<count;i++)
{
password[i]=password[i]-i-KEY;
}
return password;
}
int main()
{
char password[100];
printf("请输入需要加密的内容:");
gets(password);
encrypt(password);
printf("加密后的字符串:%s\n",password);
dencrypt(password);
printf("解密后的字符串:%s\n",password);
return 0;
}
#include <stdlib.h>
#define KEY 11 //偏移量
int encrypt(char password[])//加密
{
int i=0;
int count = strlen(password);
for(;i<count;i++)
{
password[i]=password[i]+i+KEY;
}
return password;
}
int dencrypt(char password[])//解密
{
int i=0;
int count = strlen(password);
for(;i<count;i++)
{
password[i]=password[i]-i-KEY;
}
return password;
}
int main()
{
char password[100];
printf("请输入需要加密的内容:");
gets(password);
encrypt(password);
printf("加密后的字符串:%s\n",password);
dencrypt(password);
printf("解密后的字符串:%s\n",password);
return 0;
}
本文介绍了一个使用C语言实现的简易字符串加密与解密程序。该程序通过定义一个固定的偏移量来对输入的字符串进行加密,并能逆向操作进行解密。文中提供了完整的源代码,包括加密和解密函数的定义及主函数流程。

4840

被折叠的 条评论
为什么被折叠?



