Translating the Mod Operator in VB to c++ check
-
I just want to get a check to see if my translation of the Mod Operator in VB to c++ is even close to right, or if there is a c++ equivalent to Mod, where I can just use Mod or something close to it. edit: I'm not sure if the null terminate char will produce a different result in the c++. So I have these lines of code to translate.
strTextChar = Mid(strDomainName, (i Mod Len(strDomainName)) + 1, 1)
strKeyChar = Mid(ApplicationName, (i Mod Len(ApplicationName)) + 1, 1)//vb Mod Operator = a - (b * (a / b))
szTextChar = &szDomainName[ ( i - ( wcslen(szDomainName)) * (i / wcslen(szDomainName)) ) + 1 ];
szKeyChar = &pzApplicationName[ ( i - ( wcslen(szApplicationName)) * (i / wcslen(szApplicationName)) ) + 1 ];I have this other line of code to translate, this one is more complex, just thought I would throw it out there. I took a peek at Xor, it's not quite sinking in yet.
strTextChar = Chr(Asc(strTextChar) Xor intTemp)
-
I just want to get a check to see if my translation of the Mod Operator in VB to c++ is even close to right, or if there is a c++ equivalent to Mod, where I can just use Mod or something close to it. edit: I'm not sure if the null terminate char will produce a different result in the c++. So I have these lines of code to translate.
strTextChar = Mid(strDomainName, (i Mod Len(strDomainName)) + 1, 1)
strKeyChar = Mid(ApplicationName, (i Mod Len(ApplicationName)) + 1, 1)//vb Mod Operator = a - (b * (a / b))
szTextChar = &szDomainName[ ( i - ( wcslen(szDomainName)) * (i / wcslen(szDomainName)) ) + 1 ];
szKeyChar = &pzApplicationName[ ( i - ( wcslen(szApplicationName)) * (i / wcslen(szApplicationName)) ) + 1 ];I have this other line of code to translate, this one is more complex, just thought I would throw it out there. I took a peek at Xor, it's not quite sinking in yet.
strTextChar = Chr(Asc(strTextChar) Xor intTemp)
% is the modulo operator in C++ and C# and most similar languages.
Philippe Mori
-
% is the modulo operator in C++ and C# and most similar languages.
Philippe Mori
-
I just want to get a check to see if my translation of the Mod Operator in VB to c++ is even close to right, or if there is a c++ equivalent to Mod, where I can just use Mod or something close to it. edit: I'm not sure if the null terminate char will produce a different result in the c++. So I have these lines of code to translate.
strTextChar = Mid(strDomainName, (i Mod Len(strDomainName)) + 1, 1)
strKeyChar = Mid(ApplicationName, (i Mod Len(ApplicationName)) + 1, 1)//vb Mod Operator = a - (b * (a / b))
szTextChar = &szDomainName[ ( i - ( wcslen(szDomainName)) * (i / wcslen(szDomainName)) ) + 1 ];
szKeyChar = &pzApplicationName[ ( i - ( wcslen(szApplicationName)) * (i / wcslen(szApplicationName)) ) + 1 ];I have this other line of code to translate, this one is more complex, just thought I would throw it out there. I took a peek at Xor, it's not quite sinking in yet.
strTextChar = Chr(Asc(strTextChar) Xor intTemp)
I'm trying to translate a program I use in vb to c++, to get the exact same results. The program is basically 8 lines of code. I have the first 2 lines working, but on line 3, I get back a int value of 10, and vb returns &h10, which is 16. So this is the vb loop of the function. I decided to use char since the valid characters are
Private Const VALID_CHARACTERS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
Private Const DEFAULT_FORMAT = "&&&&-&&&&-&&&&-&&&&"This is the source code from vb I use.
For i = 1 To CountAmpersands(sFormat)
L1 strTextChar = Mid(strDomainName, (i Mod Len(strDomainName)) + 1, 1)
L2 strKeyChar = Mid(ApplicationName, (i Mod Len(ApplicationName)) + 1, 1)
L3 intTemp = (((Asc(strKeyChar) * i) * Len(ApplicationName) + 1) Mod Len(ValidCharacters) + 1) 'vb returns &H10 which is 16
L4 strTextChar = Chr(Asc(strTextChar) Xor intTemp)
L5 intTemp = (((Asc(strKeyChar) * i) * Len(DomainName) + 1) Mod Len(ValidCharacters) + 1)
L6 strTextChar = Chr(Asc(strTextChar) Xor intTemp)
L7 intEncryptedChar = ((Asc(strTextChar) Xor Asc(strKeyChar)) Mod Len(ValidCharacters)) + 1
L8 strKey = strKey & Mid(ValidCharacters, intEncryptedChar, 1)Select Case i
Case 4, 8, 12
strKey = strKey & "-"
End SelectNext i
And this is my feeble translation to c++, I didn't do very good on it, this is the 3rd run.
for (int i = 1; i <= iCount; ++i) {
L1 szTextCharA = szDomainNameA[ ( i % strlen( szDomainNameA )) ]; // Correct
L2 szKeyCharA = szAppKeyA[ ( i % strlen( szAppKeyA )) ]; // Correct
L3 iTemp = ((szKeyCharA * i) * strlen(szAppKeyA)) % strlen( LICENSEKEY_CHARACTERS );//iTemp 16 or &H10
L4 szTextCharA = (char) ((int)szTextCharA ^ iTemp ); // iTemp should be 16 or &H10
L5 iTemp = (int)(szKeyCharA * i) * strlen(szDomainNameA) % strlen( LICENSEKEY_CHARACTERS );
L6 szTextCharA = (char)((int)szTextCharA ^ iTemp);
L7 iEncryptedChar = (int)szTextCharA ^ (int)szKeyCharA % strlen(LICENSEKEY_CHARACTERS);// Build up the License Key till it's done.
if ( i == 1) {
strncpy_s( szKeyA, iKeyA, &LICENSEKEY_CHARACTERS[ iEncryptedChar ], 1 );
}
else {
strncat_s( szKeyA, iKeyA, &LICENSEKEY_CHARACTERS[ iEncryptedChar ], 1 );
}} // End of for loop
Question1: On Line 3 in VB, I get back &H10, and Line 3 in c++, I get back 10. I'm not sure
-
I just want to get a check to see if my translation of the Mod Operator in VB to c++ is even close to right, or if there is a c++ equivalent to Mod, where I can just use Mod or something close to it. edit: I'm not sure if the null terminate char will produce a different result in the c++. So I have these lines of code to translate.
strTextChar = Mid(strDomainName, (i Mod Len(strDomainName)) + 1, 1)
strKeyChar = Mid(ApplicationName, (i Mod Len(ApplicationName)) + 1, 1)//vb Mod Operator = a - (b * (a / b))
szTextChar = &szDomainName[ ( i - ( wcslen(szDomainName)) * (i / wcslen(szDomainName)) ) + 1 ];
szKeyChar = &pzApplicationName[ ( i - ( wcslen(szApplicationName)) * (i / wcslen(szApplicationName)) ) + 1 ];I have this other line of code to translate, this one is more complex, just thought I would throw it out there. I took a peek at Xor, it's not quite sinking in yet.
strTextChar = Chr(Asc(strTextChar) Xor intTemp)
The second one will be something like:
strTextChar = static_cast(static_cast(strTextChar[0]) ^ intTemp);
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
-
The second one will be something like:
strTextChar = static_cast(static_cast(strTextChar[0]) ^ intTemp);
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com