資源簡介
用C++語言實現對稱密碼RC4的加密解密

代碼片段和文件信息
#include?“StdAfx.h“
#include?“rc4.h“
rc4::rc4(unsigned?char?*key_data_ptrint?nLen)
{
prepare_key(key_data_ptrnLen);
}
void?rc4::prepare_key(unsigned?char?*key_data_ptr?int?key_data_len)
{
unsigned?char?index1;
unsigned?char?index2;
unsigned?char*?state;
short?counter;
state?=?&key.state[0];
for(counter?=?0;?counter?256;?counter++)
state[counter]?=?(unsigned?char)counter;
key.x?=?0;
key.y?=?0;
index1?=?0;
index2?=?0;
for(counter?=?0;?counter?256;?counter++)
{
index2?=?(key_data_ptr[index1]?+?state[counter]?+?index2)?%?256;
swap_byte(&state[counter]?&state[index2]);
index1?=?(index1?+?1)?%?key_data_len;
}
}
void?rc4::swap_byte(unsigned?char?*a?unsigned?char?*b)
{
unsigned?char?x;
x=*a;*a=*b;*b=x;
}
void?rc4::rc4_encode(unsigned?char?*buffer_ptr?int?buffer_len)
{
unsigned?char?x;
unsigned?char?y;
unsigned?char*?state;
unsigned?char?xorIndex;
short?counter;
x?=?key.x;
y?=?key.y;
state?=?&key.state[0];
for(counter?=?0;?counter? {
x?=?(x?+?1)?%?256;
y?=?(state[x]?+?y)?%?256;
swap_byte(&state[x]?&state[y]);
xorIndex?=?(state[x]?+?state[y])?%?256;
buffer_ptr[counter]?^=?state[xorIndex];
}
key.x?=?x;
key.y?=?y;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1280??2006-09-14?11:41??RC4_CPP\RC4_CPP\rc4.cpp
?????文件????????528??2006-09-14?11:41??RC4_CPP\RC4_CPP\rc4.h
?????文件???????2044??2006-09-13?16:46??RC4_CPP\RC4_CPP\RC4_CPP.cpp
?????文件???????4295??2006-09-13?17:54??RC4_CPP\RC4_CPP\RC4_CPP.dsp
?????文件???????1335??2006-09-13?16:46??RC4_CPP\RC4_CPP\RC4_CPP.h
?????文件???????5021??2006-09-13?17:46??RC4_CPP\RC4_CPP\RC4_CPP.rc
?????文件???????4336??2006-09-14?17:39??RC4_CPP\RC4_CPP\RC4_CPPDlg.cpp
?????文件???????1430??2006-09-13?17:13??RC4_CPP\RC4_CPP\RC4_CPPDlg.h
?????文件???????3597??2006-09-13?16:46??RC4_CPP\RC4_CPP\ReadMe.txt
?????文件???????1078??2006-09-13?16:46??RC4_CPP\RC4_CPP\res\RC4_CPP.ico
?????文件????????399??2006-09-13?16:46??RC4_CPP\RC4_CPP\res\RC4_CPP.rc2
?????文件????????823??2006-09-13?17:44??RC4_CPP\RC4_CPP\resource.h
?????文件????????209??2006-09-13?16:46??RC4_CPP\RC4_CPP\StdAfx.cpp
?????文件???????1024??2006-09-13?17:53??RC4_CPP\RC4_CPP\StdAfx.h
?????文件???10144768??2010-09-26?11:29??RC4_CPP\RC4_CPP\RC4_CPP.ncb
?????文件???????2560??2010-09-26?11:29??RC4_CPP\RC4_CPP\RC4_CPP.suo
?????目錄??????????0??2006-09-13?16:46??RC4_CPP\RC4_CPP\res
?????目錄??????????0??2006-09-14?17:39??RC4_CPP\RC4_CPP
?????目錄??????????0??2010-09-26?11:28??RC4_CPP
-----------?---------??----------?-----??----
?????????????10174727????????????????????19
評論
共有 條評論