If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Encrypted = RC4("This is a test.", "Password")
For I = 1 To Len(Encrypted)
Debug.Print Hex(Asc(Mid(Encrypted, I, 1)));
Next

Thats not what i am looking for. Is there some way to do it so its like this.
Encrypted = RC4("EncryptedHexedString", "Password")
So when RC4 is decrypting it it also has to first make the hexed string to byte then decrypt it via rc4?

Actually Phil was totally on the right track. He just needed to take is a step
further with both an Encrypt and Decrypt function.
If you already have functions that perform RC4 Encrypt and Decrypt there is
no need to rewrite them, just create new functions that handle the hex
conversions and calls the original RC4 routines.

To decrypt you must reverse the process. First convert the hex characters
back to the encrypted characters and then call RC4 to decrypt them.

The changes I made to RC4() were mostly minor optimizations they have no
effect on the end results. I had not done a detailed analysis of RC4() so I
did not realize thet it reverses itself when applied to the encrypted string.
Changing the characters back and fourth from Hex() won't work the same
way, so you will need both an Encrypt and Decrypt function.

Here is the additional Decrypt routine and I included my version of RC4(),
renamed back to just RC4(), so you can play around with it.
Some changes are just cosmetic like splitting the Dim statement into
multipule Dims. I find it easier to read and later modify the code this way.
The Left$() function returns the entire string if it's not greater that the
length parameter.
All numeric variables in VB are initialized to zero, therefore they only need to
be reset if their value was ever changed.
X is only used as a loop counter and is automatically reset by each 'For'
statement.
Z is only used in one loop so it doesn't need resetting.