資源簡(jiǎn)介
c語言rc4加密算 可以對(duì)任意文件進(jìn)行加解密,自己寫的,效率很高哦

代碼片段和文件信息
#include?
#include?
void?InitS(unsigned?char?*s)
{
?int?i;
?for(i=0;i<256;i++)
??s[i]=i;
}
void?InitT(unsigned?char?*tchar?*key)
{
?int?i;
?for(i=0;i<256;i++)
??{
???t[i]=key[i%strlen(key)];
??}
}
void?Swap(unsigned?char?*sint?firstint?last)
{
?unsigned?char?temp;
?temp=s[first];
?s[first]=s[last];
?s[last]=temp;
}
void?InitPofS(unsigned?char?*sunsigned?char?*t)
{
?int?i;
?int?j=0;
?for(i=0;i<256;i++)
??{
???j=(j+s[i]+t[i])%256;
???Swap(sij);
??}
}
int?encypher(char?*sourcepathchar?*destpathchar?*key)
{
?unsigned?char?s[256]={0};
?unsigned?char?t[256]={0};
?char?buf;
?FILE?*fsource;
?FILE?*fdest;
?int?i=0;
?int?j=0;
?int?k=0;
?int?temp;
?InitS(s);
?InitT(tkey);
?InitPofS(st);
?fsource=fopen(sourcepath“rb“);
?fdest=fopen(destpath“wb“);
?buf=fgetc(fsource);
?while(buf!=EOF)
?{
??i=(i+1)%256;
??j=(j+s[i])%256;
??Swap(sij);
??temp=(s[i]+s[j])%256;
??k=s[temp];
??fputc(k^buffdest);
??buf=fgetc(fsource);
?}
??fclose(fdest);?
??fclose(fsource);
?
?printf(“\n................................\nok\n“);
?return?1;
}
int?main(int?argcchar?**argv)
{
????char?sourcepath[100]?destpath[100];
int?i;
char?key[256];
while(1)
{
printf(“Please?choose?operation:\n1:?RC4\n2:?Encrypt\n3:?Decrypt\n4:?Exit\n“);
printf(“\nchoice:“);
scanf(“%d“&i);
if(i!=4?&&?i!=1)
{
printf(“File?Path:“);
scanf(“%s“&sourcepath);
printf(“Save?Path:“);
scanf(“%s“&destpath);
printf(“Input?Key:“);
scanf(“%s“&key);
}
switch(i)
{
case?1:
printf(“..............................RC4.................................\n“);
break;
case?2:
encypher(sourcepath?destpath?key);
break;
case?3:
encypher(sourcepath?destpath?key);
break;
case?4:
default:
return;
}
printf(“\n“);
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????32768??2008-11-11?15:45??rc4\Debug\rc4.exe
?????文件?????319148??2008-11-11?15:45??rc4\Debug\rc4.ilk
?????文件?????396288??2008-11-11?15:45??rc4\Debug\rc4.pdb
?????文件??????11882??2008-11-11?15:45??rc4\rc4\Debug\BuildLog.htm
?????文件?????????67??2008-11-11?15:45??rc4\rc4\Debug\mt.dep
?????文件????????663??2008-11-11?15:45??rc4\rc4\Debug\rc4.exe.em
?????文件????????728??2008-11-11?15:45??rc4\rc4\Debug\rc4.exe.em
?????文件????????621??2008-11-11?15:45??rc4\rc4\Debug\rc4.exe.intermediate.manifest
?????文件??????13273??2008-11-11?15:45??rc4\rc4\Debug\rc4.obj
?????文件??????27648??2008-11-11?15:45??rc4\rc4\Debug\vc90.idb
?????文件??????53248??2008-11-11?15:45??rc4\rc4\Debug\vc90.pdb
?????文件???????1890??2008-11-10?19:20??rc4\rc4\rc4.c
?????文件???????3905??2008-11-10?14:11??rc4\rc4\rc4.vcproj
?????文件???????1427??2008-11-11?15:53??rc4\rc4\rc4.vcproj.CHINA-3B0AF26FA.Administrator.user
?????文件???????1427??2008-11-19?13:31??rc4\rc4\rc4.vcproj.CHINA-4820F37DB.Administrator.user
?????文件?????330752??2008-11-19?13:31??rc4\rc4.ncb
?????文件????????875??2008-11-10?14:10??rc4\rc4.sln
????..A..H.??????8704??2008-11-19?13:31??rc4\rc4.suo
?????目錄??????????0??2008-11-11?15:45??rc4\rc4\Debug
?????目錄??????????0??2008-11-11?15:45??rc4\Debug
?????目錄??????????0??2008-11-19?13:26??rc4\rc4
?????目錄??????????0??2008-11-19?13:00??rc4
-----------?---------??----------?-----??----
??????????????1205314????????????????????22
評(píng)論
共有 條評(píng)論