#include <string.h>
using namespace std;
void rc4(unsigned char * ByteInput, unsigned char * pwd,
unsigned char * &ByteOutput){
unsigned char * temp;
int i,j=0,t,tmp,tmp2,s[256], k[256];
for (tmp=0;tmp<256;tmp++){
s[tmp]=tmp;
k[tmp]=pwd[(tmp % strlen((char *)pwd))];
}
for (i=0;i<256;i++){
j = (j + s[i] + k[i]) % 256;
tmp=s[i];
s[i]=s[j];
s[j]=tmp;
}
temp = new unsigned char [ (int)strlen((char *)ByteInput) + 1 ] ;
i=j=0;
for (tmp=0;tmp<(int)strlen((char *)ByteInput);tmp++){
i = (i + 1) % 256;
j = (j + s[i]) % 256;
tmp2=s[i];
s[i]=s[j];
s[j]=tmp2;
t = (s[i] + s[j]) % 256;
if (s[t]==ByteInput[tmp])
temp[tmp]=ByteInput[tmp];
else
temp[tmp]=s[t]^ByteInput[tmp];
}
temp[tmp]=' ';
ByteOutput=temp;
}
int main()
{
unsigned char data[256] = "hello";
unsigned char pwd[256] = "2147124912";
unsigned char output[256];
rc4(data,pwd,*output);
return 0;
}
[email protected]:~/CSCI368$ g++ try.cpp -o try
try.cpp: In function ‘int main()’:
try.cpp:42:20: error: invalid initialization of non-const reference of type ‘unsigned char*&’ from an rvalue of type ‘unsigned char*’
try.cpp:5:6: error: in passing argument 3 of ‘void rc4(unsigned char*, unsigned char*, unsigned char*&)’
我試圖編譯,但我覺得我的論點3有問題rc4(data,pwd,*output);
RGD:如何通過無符號字符*
我如何通過作爲unsigned char*&
使用'的std :: string'和你的生活會更容易 – 2013-05-05 08:32:46
「如何通過無符號字符*&」 - 在一個格式正確的方式,也許? – 2013-05-05 08:33:01