? ?廣州龍躍自動化專業(yè)破解解密各類plc加密,全國24小時聯(lián)系手機:18520649527 【關(guān)技術(shù)】 微信:guanshiyou009如有任何問題請打手機或者添加微信,謝謝支持
PLC解密,全國上門PLC解密維修找龍躍自動化PLC解密網(wǎng)用c語言plc解密,專業(yè)PLC解密師傅電話153 8444 7766;提供三菱plc解密,臺達plc解密,西門子plc解密,信捷plc解密等各類PLC解密plc解密教程及觸摸屏解密維修服務,【加微信:guanshiyou009】
如何用C語言對文件進行加密和解密?
對于加密要求不高的完全可以自己定義規(guī)則來進行加密。這種加密是很簡單很自由的,例如你在存文件的時候可以將文件中的每個字符都加上一個數(shù),然后讀取該文件的時候再每個字符相應地減去那個數(shù),即可實現(xiàn)就簡單的加密,這樣你儲存的文件看上去就是亂碼了。只是這個規(guī)則太簡單,規(guī)則你可以自己定,加密與解密對著來就行了。
下面程序用異或操作對文件進行加密和解密
/******************設計思路******************/
//根據(jù)用戶輸入的加密/機密密碼,
//每次都拿原文件和密碼等長度的一個字符串和密碼
//對應元素異或進行加密/解密
//另外因為是用異或方法,所以加密和解密就是同一個程序
//即按照同樣的加密即是對文件的解密
#include
#include
#include
#include
#include
charfilename[256];//原文件
charpassword[256];//加密/解密密碼
constcharfilenametemp[]="temp15435255435325432543.temp";//加密/解密中間文件
voidinputpass(char*pass);//密碼輸入以"******"顯示
voidmain(){
FILE*fp;//加密/解密的文件
FILE*fptemp;//加密/解密過程臨時文件
intpwdlen;//密碼長度
inti=0;//計數(shù)器
charch=0;//讀入的字符
printf("請輸入要加密/解密的文件名(全路徑名):\n");
gets(filename);
if((fp=fopen(filename,"rb"))==NULL){
printf("找不到文件%s\n",filename);
exit(1);
}//if
printf("請輸入要加密/解密的密碼:\n");
inputpass(password);
pwdlen=strlen(password);
if(pwdlen==0){
printf("密碼不能為空,加密/解密失敗\n");
exit(1);
}//if
fptemp=fopen(filenametemp,"wb");//打開中間文件
while(1){
ch=fgetc(fp);//從原文件讀入一個字符
if(feof(fp)){//已經(jīng)讀到文件尾
break;//退出循環(huán)
}
ch^=password[i++];//對原字符和密碼進行異或操作
fputc(ch,fptemp);//將異或結(jié)果寫入中間文件
if(i==pwdlen){//使得原文件每和密碼長度相同的固定長度異或加密
i=0;
}
}//while
fclose(fp);//關(guān)閉打開原文件
fclose(fptemp);//關(guān)閉打開中間文件
remove(filename);//刪除原文件
rename(filenametemp,filename);//將中間文件重命名為原文件
printf("加密/解密成功\n");//至此加密/解密成功
}
//密碼輸入以"******"顯示
voidinputpass(char*pass){
inti=0;
charc;
while(isprint(c=getch())){
pass[i++]=c;
//printf("*");
}
pass[i]='\0';
printf("\n");
}
[img]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語言文件加密和解密
c語言文件加密和解密方法如下:
1、首先打開VC++6.0;
2、選擇文件,新建;
3、選擇C++ source file 新建一個空白文檔;
4、聲明頭文件
#includestdio.h
#includestdlib.h
#includestring.h
首先寫個加密函數(shù),算法就是簡介里說的;
void?EncryptFile(FILE?*sfp,FILE?*dfp,char?pwd)
{
char?ch;
if(sfp==0||dfp==0)
{
printf("ERROR!\n");
return;
}
while((ch=fgetc(sfp))!=EOF)
{
if((ch='a')(ch='z'))
{
ch=(ch-'a'+1)%26+'a';
ch=ch^pwd;
}
if((ch='A')(ch='Z'))
{
ch=(ch-'A'+1)%26+'A';
ch=ch^pwd;
}
fputc(ch,dfp);
}
}
寫解密子函數(shù):與加密的過程相反;
void?DecryptFile(FILE?*sfp,FILE?*dfp,char?pwd)
{
char?ch;
while((ch=fgetc(sfp))!=EOF)
{
if((ch='a')(ch='z'))
{
ch=ch^pwd;
ch=(ch-'a'+25)%26+'a';
}
if((ch='A')(ch='Z'))
{
ch=ch^pwd;
ch=(ch-'A'+25)%26+'A';
}
fputc(ch,dfp);
}
}
輸出函數(shù),輸出文件內(nèi)容
void?OutputFile(FILE?*fp)
{
char?ch;
while((ch=fgetc(fp))!=EOF)
putchar(ch);
}
主函數(shù),主要調(diào)用這幾個函數(shù)
int?main()
{
/*用戶輸入的要加密的文件名*/
char?sfilename[20];
/*用戶輸入加密后保存的文件名*/
char?dfilename[20];
/*用來保存密碼字符*/
char?pwd;
FILE?*sfp,*dfp;
printf("\nPlease?input?filename?to?be?encrypted:\n");
/*得到要加密的文件名*/
gets(sfilename);
/*得到加密后你要的文件名*/
printf("input?filename?to?save?the?encrypted?file:\n");
gets(dfilename);
/*得到加密字符*/
printf("Please?input?your?Password:\n");
//scanf("%c",pwd);
pwd=getch();
/*屏幕以*來表示輸入的加密字符*/
printf("*\n");
/*以只讀方式打開要加密的文件*/
if((sfp=fopen(sfilename,"r"))==0)
{
printf("Can't?open?the?file?:%s\n",sfilename);
exit(0);
}
/*輸出要加密的文件*/
printf("\nThe?the?text?of?file?to?be?encrypted?is:\n");
OutputFile(sfp);
/*建立加密后的文件*/
if((dfp=fopen(dfilename,"w+"))==0)
{
printf("Can't?open?or?create?the?file?:%s\n",dfilename);
//exit(0);
}
/*文件加密*/
fseek(sfp,0L,SEEK_SET);
EncryptFile(sfp,dfp,pwd);
printf("\n\nEncrypted?the?file?successfully!\n");
/*輸出加密后的文件*/
printf("\nAfter?encrypting?the?text?of?file?is:\n");
fseek(dfp,0L,SEEK_SET);
OutputFile(dfp);
fclose(sfp);
fclose(dfp);
getch();
return?0;
}
? ?廣州龍躍自動化專業(yè)破解解密各類plc加密,全國24小時聯(lián)系手機:18520649527 【關(guān)技術(shù)】 微信:guanshiyou009如有任何問題請打手機或者添加微信,謝謝支持