#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;
}
meme@ubuntu:~/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);
我如何通过unsigned char*&