㈠ 求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';
}
這樣加密就完結了。