473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Bit operations in ASP

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;
}

++++++++++++++++++++++++++++++++++++++
Aug 14 '06 #1
8 7571
Delphido wrote:
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.

I don't read C++, but you need to clarify what scripting language you wish
to do this in: vbscript? jscript? something else?
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 14 '06 #2
Stupid me, in vbscript...

"Bob Barrows [MVP]" wrote:
Delphido wrote:
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.


I don't read C++, but you need to clarify what scripting language you wish
to do this in: vbscript? jscript? something else?
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 14 '06 #3

"Delphido" <De******@discussions.microsoft.comwrote in message
news:D8**********************************@microsof t.com...
Stupid me, in vbscript...
In vbscript:

the modulo operator (% in C++) is MOD
the bitwise AND operator (& in C++) is AND
the XOR operator (^ in C++) is XOR

VBScript has no bitwise shift operators, however, dividing by 16 is the same
as right-shifting 4 bits (>4)

I didn't closely analyze the C++ code, but porting it may be non-trivial,
due to lack of unsigned types in VBS, and other VBS features/quirks that
protect the machine from the programmer. You should test the ported code
with a wide range of values to insure the same output.

It might be easier/faster/more reliable to write a COM object in C++ to do
the work. I'm not sure what an rstring is, you'd likely need to change that
to a BSTR, and convert from Unicode to ANSI, but the bitwise logic would
remain intact.

If you have the option, server-side JScript would be an easier port, since
its operator set mirrors C++, but the sign bit will still be an issue.

Good luck!
-Mark

"Bob Barrows [MVP]" wrote:
>Delphido wrote:
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.


I don't read C++, but you need to clarify what scripting language you
wish
to do this in: vbscript? jscript? something else?
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Aug 14 '06 #4
Mark J. McGinty wrote:
VBScript has no bitwise shift operators, however, dividing by
16 is the same as right-shifting 4 bits (>4)
Integer division: Val\16 instead of Val/16.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 14 '06 #5

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
Mark J. McGinty wrote:
>VBScript has no bitwise shift operators, however, dividing by
16 is the same as right-shifting 4 bits (>4)

Integer division: Val\16 instead of Val/16.
Indeed, thanks for clarifying.

Looking a little more closely at the OP's C++ code, it shouldn't be too
challenging, as long as no character in either the OrigString or the
KeyString has its high-order bit set, which would cause sign bit extension
in the result of the XOR op (unless of course, by chance, the high-order bit
was set in both operands) that could skew bitwise math with 8 bit value
expectations.

That *appears* to be the only danger spot -- though impossible to tell
without seeing the decrypt function as well.

-Mark

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.

Aug 14 '06 #6

"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.

Aug 14 '06 #7
Mark J. McGinty wrote:
That *appears* to be the only danger spot -- though impossible
to tell without seeing the decrypt function as well.
It isn't clear to me that you can perform integer arithmetic on strings in
VBScript, which was what I thought it was going to be used for.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 15 '06 #8

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:Ou**************@TK2MSFTNGP06.phx.gbl...
Mark J. McGinty wrote:
>That *appears* to be the only danger spot -- though impossible
to tell without seeing the decrypt function as well.

It isn't clear to me that you can perform integer arithmetic on strings in
VBScript, which was what I thought it was going to be used for.
One character at a time, using Asc() and Chr()... <shrug>? Should be
possible as long as all calc results are kept inside of 7 bits -- or both
encrypt and decrypt functions are written in VBS.

In C++ elements in a character array aren't assumed to be part of a text
string until output/display time; defining a character in single quotes is
merely a notation option, 'a', 97 and 0x61 are binary equivilents, and
equally legal rvalues when assigning a char.

But in VBS, character data isn't quite so unfettered, string assumptions are
imposed by notation, thus the need to "convert" a character back to what it
actually already is, to act on it arithmetically. :-)
-Mark
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.

Aug 16 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
3
by: Scott Brady Drummonds | last post by:
Hello, all, My most recent assignment has me working on a medium- to large-sized Windows-based C++ software project. My background is entirely on UNIX systems, where it appears that most of my...
3
by: ThunderMusic | last post by:
Hi, I have 2 UInt64 to add and then divide the result by another value. How can I do this? because the math operators have not been defined for UInt64. Can somebody help please? Thanks ...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
13
by: Immanuel Goldstein | last post by:
Obtained under the Freedom of Information Act by the National Security Archive at George Washington University and posted on the Web today, the 74-page "Information Operations Roadmap" admits that...
36
by: mrby | last post by:
Hi, Does anyone know of any link which describes the (relative) performance of all kinds of C operations? e.g: how fast is "add" comparing with "multiplication" on a typical machine. Thanks!...
3
by: Hallvard B Furuseth | last post by:
I'm wondering how to design this: An API to let a request/response LDAP server be configured so a user-defined Python module can handle and/or modify some or all incoming operations, and later...
6
by: carsonbj | last post by:
I have an issue where the below operation works on a little-endian architecture but not on a big-endian architecture. I was under the impression that pointer arithmetic is architecture independant...
4
by: alex | last post by:
hi friends ... i am facing a problem while detecting floating point operations in my project, please help me. i want to find out the places in my C/C++ project where i am doing floating...
0
by: tabassumpatil | last post by:
Please send the c code for: 1.STACK OPERATIONS : Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2. 2.QUEUE OPERATIONS : Write a program to implement...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.