c语言使用函数加密数组 c语言加密解密数字

用C语言编程恺撒密码加密解密程序#include stdio.h
#define isletter( c )( ((c)='a'(c)='z') || ((c)='A'(c)='Z') )
void Enc( const char *str, char *out, int key )
{
int i = 0;
while( str[i] )
{
if ( isletter( str[i] ) )
{
out[i] = str[i] + key;
if ( ! isletter( out[i]))
out[i] -= 26;
}
else
out[i] = str[i];
i++;
}
out[i] = 0;
}
void Denc( const char *str, char *out, int key )
{
int i=0;
while( str[i] )
{
if ( isletter( str[i] ) )
{
out[i] = str[i] - key;
if ( ! isletter( out[i] ) )
out[i] += 26;
}
else
out[i] = str[i];
i++;
}
out[i] = 0;
}
int main()
{
charout[100], out2[100];
Enc( "THE QUICK BROWn fox jumps over THE LAZY DOG", out, 3 );
printf( "%s\n", out );
Denc( out, out2, 3 );
printf( "%s\n", out2 );
}
c语言编写字符串加密函数 不要写得太难啊#include stdio.h
#include ctype.h
char *encrypt(char *text) {
char c;
char *p = text;
for (; *text; ++text) {
c = *text;
if (isdigit(c))
*text = '0' + '9' - c;
else if (islower(c)) {
c = c + 3;
if (c'z')
c = c - 26;
*text = c;
} else if (isupper(c)) {
c = c + 3;
【c语言使用函数加密数组 c语言加密解密数字】if (c'Z')
c = c - 26;
*text = c;
}
}
return p;
}
int main() {
char text[100];
printf("输入明文:");
scanf("%s", text);
printf("密文:%s\n", encrypt(text));
getchar();
}
C语言设计一个简单的加密解密程序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语言中的数据加密(跪求)下面是个例子,对12345678加密 。
想对哪个8位数加密,调ProcessInt这个函数就可以了 。
如果8位内的任意整数的话,楼主做做改动即可,不难实现 。
程序考虑到让楼主看的清楚,并没有将效率写到最大 。
#include stdio.h
#include iostream
#include windows.h
#include math.h
using namespace std;
void ProcessInt(int* piInt)
{
int iArray[8];
int iResult = (*piInt);
int iTmp = *piInt;
for (int i = 0; i8; i++)
{
iResult = iResult / (int)pow(10, 8 - 1 - i);
iArray[i] = iResult;
iResult = iTmp - iResult * (int)pow(10, 8 - 1 - i);
iTmp = iResult;
}
//1.sequence
//2.replace the number by plus 5 and then div 10
for (int i = 0; i8; i++)
{
iArray[i] = (iArray[i] + 5) % 10;

推荐阅读