RC4 Encyption, Bad PTR

Can anyone help as to why ByteOuput is giving me a BadPTR error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

void rc4(unsigned char * ByteInput, unsigned char * pwd, unsigned char * &ByteOutput)
{
	
    temp[tmp]= '\0';
    
    for (tmp = 0; tmp < (int)strlen((char *)ByteInput); tmp++)	//copy ciphertext to output
        ByteOutput[tmp] = temp[tmp];
    delete temp;
}


//EDIT ONLY showing last part..
Last edited on
Tried taking out the & reference operator in the rc4 parameters, that doesn't work either.
You have not allocated any memory for encrypted or decrypted.

Try this in rc4:
1
2
3
4
5
6
    temp[tmp]= '\0';
    ByteOutput = temp;
//    for (tmp = 0; tmp < (int)strlen((char *)ByteInput); tmp++)	
//        ByteOutput[tmp] = temp[tmp];
//    delete temp;
}
That at least got the program to runbut the output is messed up...

Message: Hello world!
Password: abc
Message encrypted: αF
Message decrypted: ≈╪←└≈╪YH]├ÉÉÉÉÉΦ▀ú∙ â└d├ÉÉÉÉÉΦ╤ú∙ â└`├ÉÉÉÉÉj$hH■=uΦ▄¥∙ 3 ë}╘ë
}Σï▀ë]╪ïâ■♂⌂Mt§ï╞j☻Y+┴t"+┴+┴tc+┴uEΦFú∙ ï╪ë]╪à█u▬â╚ Θi☺

--------------------------------
Process exited with return value 0
Press any key to continue . . .


Thanks by the way for the start.
Strange. If I make that change I get the following output:
Message: Hello world!
Password: abc
Message encrypted: ���E7��^� �
Message decrypted: Hello world!
Topic archived. No new replies allowed.