|
-
Jan 23rd, 2011, 12:09 PM
#1
Thread Starter
New Member
Help convert a string modification code from C++ to VB
Hi all.
I have written a C++ code to modify a string, the code is:
Code:
int Len = (nString.length());
char *szString = (char*)(nString.c_str()); // Convert to C string
for (int i = 0; i < Len; i++)
{
*(szString+i) = (*(szString+i) + 123); //XOR
}
Can someone help me convert this to VB:
I have this so far, but it is not working:
Code:
Dim i As Integer
Dim chrArray() As Char
chrArray = EncryptIn.ToCharArray
For intCounter = 0 To chrArray.Length - 1
chrArray(i) = chrArray(i + 123)
Next
Thanks bunch!
-
Jan 23rd, 2011, 12:33 PM
#2
Re: Help convert a string modification code from C++ to VB
What does "it is not working" mean exactly? Do you get an error? Does something occur that you're not expecting? What are you expecting?
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 05:34 PM
#3
Re: Help convert a string modification code from C++ to VB
The line within the loop should be:
Code:
chrArray(i) = chrArray(i) + 123
Nah - that doesn't compile - I have no idea what you're trying to do with that original C++ code - could you explain?
Last edited by David Anton; Jan 23rd, 2011 at 05:46 PM.
-
Jan 23rd, 2011, 07:52 PM
#4
Re: Help convert a string modification code from C++ to VB
Does this work?? Or does VB throw an overflow??
Code:
charArray(i) += ChrW(123)
In C# you could use this
Code:
charArray[i] += (char)123;
And I think the C++ could be rewritten as
Code:
szString[i] += 123;
-
Jan 23rd, 2011, 09:13 PM
#5
Re: Help convert a string modification code from C++ to VB
I think the loop line should read:
Code:
chrArray(i) = Chr(Asc(chrArray(i)) Xor 123)
?
-
Jan 23rd, 2011, 09:33 PM
#6
Thread Starter
New Member
Re: Help convert a string modification code from C++ to VB
 Originally Posted by David Anton
The line within the loop should be:
Code:
chrArray(i) = chrArray(i) + 123
Nah - that doesn't compile - I have no idea what you're trying to do with that original C++ code - could you explain?
 Originally Posted by weirddemon
What does "it is not working" mean exactly? Do you get an error? Does something occur that you're not expecting? What are you expecting?
Thanks for helping guys, what I expect is to do some simple mathematical operation to the char bytes to encrypt the string
for example:
If I have string = "abc", and when I do this (in C++)
Code:
for (int i = 0; i < Len; i++)
{ *(szString+i) = (*(szString+i)+1); }
The string will become "bcd", so obviously for the real code I will have much more complicated formula to generate the new string
I hope this makes sense now, basically is the ability to do char # of each character one by one in the string
Last edited by boardgg; Jan 23rd, 2011 at 09:44 PM.
-
Jan 23rd, 2011, 10:47 PM
#7
Thread Starter
New Member
Re: Help convert a string modification code from C++ to VB
 Originally Posted by Evil_Giraffe
I think the loop line should read:
Code:
chrArray(i) = Chr(Asc(chrArray(i)) Xor 123)
?
Hello.
I tested with
Code:
chrArray(i) = Chr(Asc(chrArray(i)) + 1)
and that is what I wanted, however when I tried to do more complicated calculation, such as Chr(Asc(chrArray(i)) Xor 123456) I got error of "Procedure call or argument is not valid"
Any idea why? Seems the number is outside of Chr()'s range (max 65536)? I actually do want to xor with a huge number, in c++ it works.
thanks!
Last edited by boardgg; Jan 23rd, 2011 at 11:07 PM.
-
Jan 24th, 2011, 06:33 PM
#8
Thread Starter
New Member
Re: Help convert a string modification code from C++ to VB
Sorry about bumping this myself, really in need of a solution to this
basically is how to get chr() of value greater than 65536?
thanks!
-
Jan 25th, 2011, 09:31 PM
#9
Re: Help convert a string modification code from C++ to VB
Basically you can't, and you can't in C++ either.
Your question could be reworded as 'How can I fit more than 2 bytes into 2 bytes'
C++ allows you to overflow numbers silently, VB.net doesn't.
If you want to Xor a char with a large number try using a bitwise And &hFFFF with it first to truncate it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|