This project has moved. For the latest updates, please go here.
2
Vote

Get MachineCode with value of 100000

description

I generated machine code on a client computer today and got the value of 100000. That number is incorrect and all licenses are invalid as well.

I think there is a bug in your code. Let take these lines from function getEightByteHash()
int result = (int)(hash % MUST_BE_LESS_THAN);
int check = MUST_BE_LESS_THAN / result;

if (check > 1)
{
    result *= check;
}

return result;
I don't change MUST_BE_LESS_THAN so its value is 100000
If hash is 1000 so check equals MUST_BE_LESS_THAN and the returned value is 100000

comments

artemlos wrote Feb 22, 2015 at 8:34 PM

I think I was able to reproduce this bug. I will see what can be done. Thank you for reporting! Sorry for such a late reply.

wrote Feb 22, 2015 at 8:36 PM

artemlos wrote Feb 23, 2015 at 7:22 AM

I did some some quick changes, here is the updated code:
       /// <summary>
        /// This method will generate an 8 digit long hash which can be stored as an Int32.
        /// </summary>
        /// <param name="s">The string value of the infromation that is to be hashed.</param>
        /// <returns>A string with the hash value</returns>
        public static string getEightDigitsLongHash(string s)
        {
            //This function generates a eight byte hash

            //The length of the result might be changed to any length
            //just set the amount of zeroes in MUST_BE_LESS_THAN
            //to any length you want
            uint hash = 0;

            int MUST_BE_LESS_THAN = 100000000;//1000000;

            foreach (byte b in System.Text.Encoding.Unicode.GetBytes(s))
            {
                hash += b;
                hash += (hash << 10);
                hash ^= (hash >> 6);
            }

            hash += (hash << 3);
            hash ^= (hash >> 11);
            hash += (hash << 15);

            int result = (int)(hash % MUST_BE_LESS_THAN);

            //we want the result to not be zero, as this would thrown an exception in check.
            if (result == 0)
                result = 1;


            int check = MUST_BE_LESS_THAN / result;

            if (check > 1)
            {
                result *= check;
            }

            //when result is less than MUST_BE_LESS_THAN, multiplication of result with check will be in that boundary.
            //otherwise, we have to divide by 10.
            if (MUST_BE_LESS_THAN == result)
                result /= 10;
                

            return result.ToString();
        }

        [TestMethod]
        public void LengthEight()
        {
            int MUST_BE_LESS_THAN = 100000000;//1000000;

            //assuming not zero.
            for (int i = 0; i < 1000000000; i++)
            {
                long hash = i;

                int result = (int)(hash % MUST_BE_LESS_THAN);

                if (result == 0)
                    result = 1;

                int check = MUST_BE_LESS_THAN / result;

                if (check > 1)
                {
                    result *= check;
                }

                if (MUST_BE_LESS_THAN == result)
                    result /= 10;
                

                if (result.ToString().Length != 8)
                    Assert.Fail();

            }
            
        }
The test method is there to test for different values from 0 to MUST_BE_LESS_THAN in order to ensure that a string of the desired length is returned. If you have the time, I would recommend you to replace this method with the one in SKGL. Keep in mind that the value of the MUST_BE_LESS_THAN might different in SKGL and the code above, but you should use the one in SKGL.

I really hope I will have the time this week to implement this fix and an improvement to SKGL machine code function (the one that collects the data).

Again, thank you for reporting this!

pleonardomv wrote Dec 13, 2016 at 7:55 AM

Hi,
I'm starting in .NET. I have now found this dll. Do you have a newer version?

Regards