"Delphido" <De******@discussions.microsoft.comwrote in message

news:BE**********************************@microsof t.com...

Hello,

i've been programming ASP for a few years, but this time i'm lost..

I need to translate a piece of C++ code which encrypts a string into the

ASP

equivalent. Can anybody give me a had with this. I have nog clue about

bit-operations etc, and don't no to much about C++ as well..

+++++++++++++++ C++ code +++++++++++++++

rstring Encrypt_String( const rstring& OrgString, const rstring&

KeyString)

{

rstring Result;

unsigned char* pKey;

unsigned char Val;

unsigned char ValRes;

int LenOrg = OrgString.GetLength();

int LenKey = KeyString.GetLength();

const char* pConvert = OrgString;

for( int i=0; i< LenOrg; ++i, ++pConvert)

{

Val = *pConvert ^ KeyString[ i % LenKey];

ValRes = 'a' + ((Val >4) & 0x0F);

Result.add( (const char*)&ValRes, 1);

ValRes = 'a' + (Val & 0x0F);

Result.add( (const char*)&ValRes, 1);

}

return Result;

}

++++++++++++++++++++++++++++++++++++++

This is a best guess:-

Function EncryptString(PlainText, KeyText)

Dim lKeyLen: lKeyLen = Len(KeyText)

Dim i

Dim bytA : bytA = AscB("a")

Dim bytVal

Dim asRes: ReDim asRes(Len(PlainText)*2)

For i = 1 To Len(PlainText)

bytVal = AscB(Mid(PlainText, i, 1)) Xor AscB(Mid(KeyText, (i Mod

lKeyLen)+1,1))

asRes((i-1)*2) = Chr(bytA + (bytVal \ 16))

asRes((i-1)*2+1) = Chr(bytA + (bytVal And &h0F))

Next

EncryptString = Join(asRes,"")

End Function

Function DecryptString(CryptText, KeyText)

Dim lKeyLen: lKeyLen = Len(KeyText)

Dim i

Dim bytA : bytA = AscB("a")

Dim bytVal

Dim asRes: ReDim asRes(Len(CryptText) \ 2)

For i = 2 To Len(CryptText) Step 2

bytVal = (AscB(Mid(CryptText, i - 1, 1)) - bytA) * 16

bytVal = bytVal Or ((AscB(Mid(CryptText, i, 1)) - bytA) And &H0F)

bytVal = bytVal Xor AscB(Mid(KeyText, ((i \ 2) Mod lKeyLen)+1,1))

asRes(i \ 2) = Chr(bytVal)

Next

DecryptString = Join(asRes,"")

End Function

Works fine if these matching functions are used. However if you have the

C++ code on the decrypt end then it should still work for purely ASCII codes

but extended ANSI characters may have trouble passing through and you can

forget about the full extended unicode character set.