C語言(檔案加解密)

2021-09-11 13:22:35 字數 1385 閱讀 7806

在c語言,檔案主要分為文字檔案和二進位制檔案,因此主要是對這兩種檔案進行加解密。

原檔案

/*

加密對每乙個字元進行 異或運算

規則:1^1=0, 0^0=0, 1^0=1, 0^1=1 同為0,不同為1

*/void crpypt(char file_path,char crpypt_path )

//關閉

fclose(file_p);

fclose(crpy_p);

printf("加密完成");

}複製**

void main

()複製**

得到加密檔案

文字檔案解密

void decrpypt(char crypt_path, char decrypt_path)

//關閉

fclose(crpypt_p);

fclose(decrpypt_p);

printf("解密完成");

}複製**

void main

()複製**

解密得到的檔案

二進位制檔案加密

/*

二進位制檔案加解密

讀取二進位制檔案中的資料時,乙個乙個字元讀取

對每乙個字元進行 異或運算

*//*

二進位制檔案加解密

讀取二進位制檔案中的資料時,乙個乙個字元讀取

對每乙個字元進行 異或運算

*/void crpypt(char file_path, char crpypt_path, char password)

//關閉

fclose(file_p);

fclose(crpy_p);

printf("加密完成");

}複製**

/*

密碼:password

*/void main

()複製**

原檔案

加密後

二進位制檔案解密

//解密

void decrpypt(char crypt_path, char decrypt_path, char password)

//關閉

fclose(crpypt_p);

fclose(decrpypt_p);

printf("解密完成");}/*

密碼:password

*/void main

()複製**

執行結果:

以上就是使用異或運算對檔案進行加解密的例項。

c語言簡單加解密

include include includeint dofile char in fname,char pwd,char out fname 對檔案進行加密的具體函式 簡單檔案異或加解密。infile pwd outfile int main int argc,char argv 定義main 函...

C 檔案簡單加解密

include include includevoid encfile char in filename,char pwd,char out filename 對檔案進行加密的具體函式 void decryptfile char in filename,char pwd,char out filen...

檔案加解密

建立debuglzq 密碼 加密物件 private static symmetricalgorithm createrijndael string password,byte salt 加密檔案隨機數生成 private static randomnumbergenerator rand new ...