September 20, 201212 yr Author HelloPlease there is anyone who can translate for me a code writen in Vb.net and csharp to c++ (or even to Vb 6 or even to vb net !! as i did not come to solve it) and make the that code work.in fact this code snippet is a keygen code procdedure :take a name in editBoxtext1 and put it in VAR Nom and pass it to to Serial subRoutine and the result is a serial is desplayed in editBox2textthat is all , so simple ..The result would be :nom : yanoserial: 463375942--code snippet----vb net ?? Public Function A0(ByVal nom As String) As Integer nom = nom.ToUpper Dim num As Integer = 0 Dim i As Integer For i = 0 To nom.Length - 1 num = (num + (nom.Chars(i) * nom.Chars(i))) Next i num = ((num * num) * num) Return (Math.Abs(CInt((num - (num Mod &H7D6)))) + &H7BA)End Function --code snippet----csharp ?? public int A0(string nom){ nom = nom.ToUpper(); int num = 0; for (int i = 0; i < nom.Length; i++) { num += nom * nom; } num = (num * num) * num; return (Math.Abs((int) (num - (num % 0x7d6))) + 0x7ba);}Thanks yano
September 21, 201212 yr Something like this should work in C++#include <Windows.h>#include <algorithm>#include <math.h>#include <string>int A0( const std::string& str ){ std::string upp = str; std::transform( upp.begin(), upp.end(), upp.begin(), ::toupper ); int nReturn = 0; const char* pszString = upp.c_str(); for( unsigned int x = 0; x < upp.size(); x++ ) { nReturn += pszString[x] * pszString[x]; } nReturn = ( nReturn * nReturn ) * nReturn; return ( abs( (int)( nReturn - ( nReturn % 0x7D6 ) ) ) + 0x7BA );}int __cdecl main( int argc, TCHAR* argv[] ){ std::string str( "This is a string to test." ); int nTest = A0( str ); return 0;} Edited September 21, 201212 yr by atom0s
September 22, 201212 yr Author Hi I thank you so much lol.I will try that code and inform you of its working. Newbie Thanks
September 25, 201212 yr Author Hello AtomsI tryed to translate another Snippet with a slight difference en serial routine but did nort work : ERROR : DIVISION BY ZERO !!I paste here the code in csharp (from Reflector) :public static long m000219(string p0){ p0 = p0.ToUpper(); long num = 0L; for (int i = 0; i < p0.Length; i++) { num += p0 * p0; } num = ((num * num) * num) % ((long) Math.Pow(2.0, 32.0)); num -= (long) Math.Pow(2.0, 32.0); if (num < ((long) (-Math.Pow(2.0, 32.0) / 2.0))) { num += (long) Math.Pow(2.0, 32.0); } return (Math.Abs((long) (num - (num % 0x837L))) + 0x16f7L);}--Translated en c++ but fail :Edivbyzero exeption :#include <algorithm>#include <math.h>#include <string>long serial( const std::string& str ){ std::string upp = str; std::transform( upp.begin(), upp.end(), upp.begin(), ::toupper ); long nReturn = 0L; const char* pszString = upp.c_str(); for( unsigned int x = 0; x < upp.size(); x++ ) { nReturn += pszString[x] * pszString[x]; } nReturn = (( nReturn * nReturn ) * nReturn) % ((long)pow(2.0,32.0)); nReturn -= (long)pow(2.0, 32.0); if (nReturn < ((long) (-pow(2.0, 32.0) / 2.0))) { nReturn += (long)pow(2.0, 32.0); } return (abs((long) (nReturn - (nReturn % 0x837L))) + 0x16f7L); }//int __cdecl main( int argc, TCHAR* argv[] ) { std::string str( "This is a string to test." ); long nTest = serial( str ); return 0; }thanks for reply
September 25, 201212 yr char *strtoupper(char *p){ char *s=p; while( *s ) { *s=toupper((unsigned char) *s); ++s; } return p;}long long m000219(char* text){ int len = strlen(text); int i = 0; long long num = 0; long long x = pow(2.0,32.0); text = strtoupper(text); for (i = 0 ; i<=len; i++) { num += text[i] * text[i]; } num = (num * num * num) % x; num -= x; if (num < ((-x) >> 1)) { num += x; } num = ((~num) - ((~num) % 0x837) + 0x16f7); return num;}hope it helps Edited September 25, 201212 yr by sama
September 26, 201212 yr Following my similar method with the STL:#include <Windows.h>#include <algorithm>#include <string>#include <math.h>static long m000219( const std::string& str ){ std::string upp = str; std::transform( upp.begin(), upp.end(), upp.begin(), ::toupper ); long num = 0L; const char* pszString = upp.c_str(); for (long i = 0; i < upp.size(); i++) { num += pszString[i] * pszString[i]; } num = (( num * num ) * num) % ( (long)pow( 2.0f, 32.0f ) ); num -= (long)( pow( 2.0f, 32.0f ) ); if (num < ( (long)-pow( 2.0f, 32.0f ) / 2.0f ) ) { num += (long)( pow( 2.0f, 32.0f ) ); } return ( abs( (long)( num - ( num % 0x837L ) ) ) + 0x16F7L );}int __cdecl main( int argc, TCHAR* argv[] ){ std::string str( "This is a string to test." ); long nTest = m000219( str ); return 0;}Grr stupid forum formatting sucks lol.. Edited September 26, 201212 yr by atom0s
September 27, 201212 yr Author Hi SAMAThe code works fine but sometimes when changing the string the result is a negative number ! so i changed the code :num = ((~num) - ((~num) % 0x837) + 0x16f7); To : num= (abs((long long)( num - ( num % 0x837 ) )) + 0x16f7 ); // and works 100%Thanks SameNewbie yano
September 27, 201212 yr Author Hi atom0s The code does not work : stepping the line code : num = (( num * num ) * num) % ( (long)pow( 2.0f, 32.0f ) ); a message of error : Idivbyzero exception is desplayed. please helpme to solve it. Thanks for you reply and your help . thanks Newbie yano Edited September 27, 201212 yr by yano65bis
September 27, 201212 yr It's because in C# long is 64bit integer but in C++ it's 32bits. Use "long long" instead.
Create an account or sign in to comment