㈠ 求c语言程序设计 数据加密详解~!!!
#include<stdio.h>
#define
N
8
void
main()
{
int
code,count,i,temp;
int
key[N];
printf("请输入密码:");
scanf("%d",&code);
//各位交换
i=0;
count=0;
while(code!=0)
{
key[i]=code%10;
code
/=
10;
i++;
count++;
}
//各位
加5,并对其取余
for(i=0;i<count;i++)
{
key[i]
+=
5;
key[i]
%=
10;
}
//数字第一位与最后一位互换
temp
=
key[0];
key[0]
=
key[count-1];
key[count-1]
=
temp;
for(i=0;i<count;i++)
{
printf("%d
",key[i]);
}
}
//晕...你是北大青鸟的吧..我昨天刚做了这个项目.刚好发给你了..
㈡ c语言 数据加密
什么是异或算法
异或的特点是原始值经过两次异或某一个数后会变成原来的值,所以有时利用这个特性来进行加密,加密端把数据与一个密钥进行异或操作,生成密文。接收方收到密文后利用加密方提供的密钥进行再次异或操作就能得到明文。
例程:
/*以DWORD为单位对文件进行加密,将每个DWORD与0xfcba0000(密钥)做异或,写入另一个文件*/
#include<stdio.h>
#include<stdlib.h>
#defineDWORDunsignedlong
#defineBYTEunsignedchar
#definefalse0
#definetrue1
intmain(intargc,char*argv[])
{
FILE*hSource;
FILE*hDestination;
DWORDdwKey=0xfcba0000;
char*pbBuffer;
DWORDdwBufferLen=sizeof(DWORD);
DWORDdwCount;
DWORDdwData;
if(argv[1]==0||argv[2]==0)
{
printf("missingargument!
");
returnfalse;
}
char*szSource=argv[1];
char*szDestination=argv[2];
hSource=fopen(szSource,"rb");//打开源文件.
hDestination=fopen(szDestination,"wb");//打开目标文件
if(hSource==NULL){printf("openSourceFileerror!");returnfalse;}
if(hDestination==NULL){printf("openDestinationFileerror!");returnfalse;}
//分配缓冲区
pbBuffer=(char*)malloc(dwBufferLen);
do{
//从源文件中读出dwBlockLen个字节
dwCount=fread(pbBuffer,1,dwBufferLen,hSource);
//加密数据
dwData=*(DWORD*)pbBuffer;//char*TOdword
dwData^=dwKey;//xoroperation
pbBuffer=(char*)&dwData;
//将加密过的数据写入目标文件
fwrite(pbBuffer,1,dwCount,hDestination);
}while(!feof(hSource));
//关闭文件、释放内存
fclose(hSource);
fclose(hDestination);
printf("%sisencryptedto%s
",szSource,szDestination);
return0;
}
㈢ c语言数字后移加密
#include<stdio.h>
intmain()
{
inta,b;
scanf("%d",&a);
b=0;
do
{
b=b*10+(a%10+2)%10;
a/=10;
}while(a);
for(a=0;b;b/=10)
{
a=a*10+b%10;
}
printf("%d ",a);
return0;
}
㈣ C语言程序设计 简单加密程序
你的改动不可以,之所以你的调试结果对,那是因为你没有用边界值去测试。
这个加密方法是用的循环码,也就是用字母推后两个位置,即用C代替A,用D代替B,那么Z用什么来代替呢?那就是B。除以26的目的就是当超过26后,通过求余数的方式折回头部去。
(soustr[j]-'A'+2)的意思就是将26个字母编号为1~26。
㈤ c语言编写程序,并加密数据
#include<stdio.h>
void passwordnum(long a);
int main(void)
{
long num;
while(!scanf("%d",&num))
{
while(getchar()!='\n'); //把数字后面的不纯净输入吸收掉
printf("Input Error! please retry anain.\n");
}
passwordnum(num);
printf("\n");
return 0;
}
void passwordnum(long a)
{
if(a>0)
{
passwordnum(a/10);
printf("%d",(a+2)%10);
}
else if(a<0)
{
printf("-");
a=-a;
passwordnum(a);
}
}
㈥ C语言 循环加密求助
/**********************************
**File: Encry1.C
**Use: Simple Encrytion for a String
**Author: Burea
**Create Date: Nov 7th, 2007
**Last Edit:
**********************************/
#include <stdio.h>
int Encrypt(char*, int);
int main()
{
char sSrc[256] = { 0 };
int iKey = 0;
printf("Please input a string to be encrypted:\n");
scanf("%s", sSrc);
printf("Please input a number for encryption:\n");
scanf("%d", &iKey);
if ( Encrypt( sSrc, iKey ))
printf("Cryptograph: %s\n", sSrc);
else
printf("No Source String for Encryption.\n");
getch();
return 0;
}
int Encrypt(char* sEn, int iKey)
{
int i = 0;
int ilen = strlen(sEn);
if ( !ilen )
return 0;
for (i=0; i<ilen; i++)
{
int t = *(sEn+i); /*Transform char to int to get ASCII code*/
if (t>=65 && t<=90)
{
t = (t - 65 + iKey%26)%26; /*Get encryption uppercase ASCII code*/
t = (t>=0?t:(t+26)) + 65;
}
else if (t>=97 && t<=122)
{
t = (t - 97 + iKey%26)%26;/*Get encryption lowercase ASCII code*/
t = (t>=0?t:(t+26)) + 97;
}
else /*If other case, neglect*/
continue;
/*Get encryption ASCII character*/
*(sEn+i) = t;
}
return 1;
}
㈦ C语言数字加密
#include
void
main()
{
int
a[5];
/*
存储各位上的数字
*/
int
num,
temp,
encripy;
/*
num是要输入的数,temp是交换时用来存储临时值,encripy是加密后的数据
*/
int
i;
do
{
printf("please
input
the
number:");
scanf("%d",&num);
if(!(num/10000
!=0
&&
num/100000==0))
printf("data
error!\n");
}while(!(num/10000
!=0
&&
num/100000==0));
a[0]
=
num/10000%10;
/*
求各位上的数字
*/
a[1]
=
num/1000%10;
a[2]
=
num/100%10;
/*
百位上的数字
*/
a[3]
=
num/10%10;
/*
十位上的数字
*/
a[4]
=
num%10;
/*
个位上的数字
*/
for(i
=
0;
i
<
5;
++i)
/*
开始加密
*/
a[i]
=
(a[i]
+
8)%10;
temp
=
a[0];
/*
交换位置开始
*/
a[0]
=
a[3];
a[3]
=
temp;
temp
=
a[1];
a[1]
=
a[2];
a[2]
=
temp;
/*
交换位置结束同时加密结束
*/
encripy
=
a[0]*10000
+
a[1]*1000
+
a[2]*100
+
a[3]*10
+
a[4];
/*
加密后的数据
*/
printf("\nthe
scourse
number:
%d\n",
num);
/*
输出原数据
*/
printf("\nencripy
the
number:
%d\n\n",
encripy);
/*
输出加密后的数据
*/
}
在vc6.0成功运行,希望对你有帮助!
㈧ C语言字符串按要求加密 求教
void encryp(char *plain,char *cipher)这个函数你写复杂了,如下就可以了——
void encryp(char *plain,char *cipher){
int i;
for(i=0;plain[i];i++)
cipher[i]=plain[i]-24;
cipher[i]='\0';
}
这样加密就完结了。