資源簡介
使用RC4加密算法對文件進行加密或者解密,C語言實現
代碼片段和文件信息
#include?
#include?
#include?
#define?FNAME?30
void?Initial(char?*);????//初始化的函數
unsigned?int?S[256];????//?S數組
int?main()
{
char?FNameR[FNAME]FNameW[FNAME];????//用于存儲文件路徑的數組
FILE?*rFile?*wFile;????//文件指針
char??rChar=0wChar=0;????//一個要讀取的字符,一個要寫入的字符????
char?opttemk;
long?int?last=0;????//要讀取的文件的長度
char?key[257];????//密鑰
//用戶輸入部分
printf(“…………………………?RC4?Cipher?…………………………“);
printf(“\n\nWhich?do?you?want?to?do?encryption?or?decryption???“);????//選擇加密或解密
printf(“\n(Enter?e?or?d):?“?);
scanf(“%c“&opt);
fflush(stdin);????//清空輸入流
printf(“Please?enter?a?file?path?to?read:?“);????//輸入讀文件的路徑
gets(FNameR);
rFile=fopen(FNameR“rb“);
if?(rFile==NULL)????//如果打開文件失敗,提示用戶
{
printf(“\nFailed?to?open?the?file?to?read.“);
exit(1);
}
printf(“Please?enter?a?file?path?to?write:?“);????//輸入寫文件的路徑
gets(FNameW);
wFile=fopen(FNameW“wb“);
if?(wFile==NULL)????//如果打開文件失敗,提示用戶
{
printf(“\nFailed?to?open?the?file?to?write.“);
exit(1);
}
printf(“Please?enter?the?key?(less?than?256):?“);????//輸入密鑰
gets(key);
printf(“你輸入的密鑰是:“);
puts(key);
????//程序的輸出部分
printf(“\n**********************?Output?**********************“);
????fseek(rFile0LSEEK_SET);?????//移到讀取文件的開始
fseek(rFile0LSEEK_END);?????//
評論
共有 條評論