Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. How to Generate a 16 bit Random number?

How to Generate a 16 bit Random number?

Scheduled Pinned Locked Moved IT & Infrastructure
questionhelptutoriallounge
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Affan Toor
    wrote on last edited by
    #1

    Hi! i want to generate a 16 bit license key for my product, but have no idea how to do it? Each bit of number will refer to a feature of product. can any body tell me how can i achieve this task? i have no idea from where to start and what to do....please help..!!! Thanks in advance... Regards, Affan Ahmad Toor

    D P M 4 Replies Last reply
    0
    • A Affan Toor

      Hi! i want to generate a 16 bit license key for my product, but have no idea how to do it? Each bit of number will refer to a feature of product. can any body tell me how can i achieve this task? i have no idea from where to start and what to do....please help..!!! Thanks in advance... Regards, Affan Ahmad Toor

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      16 bits for a license key? That's useless. For numbers alone, that's 65535 different key's MAXIMUM. Now, turn some of those bits on and off to signal various program options, and you've got considerably fewer license numbers you can use. For examples and commercial products that do this, just Google for "vb.net license key generation[^]". All of them will use considerably more than 16 bits.

      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • A Affan Toor

        Hi! i want to generate a 16 bit license key for my product, but have no idea how to do it? Each bit of number will refer to a feature of product. can any body tell me how can i achieve this task? i have no idea from where to start and what to do....please help..!!! Thanks in advance... Regards, Affan Ahmad Toor

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Or if you really want a 16 bit random value, simply use short x = (short) (new System.Random()).Next ( 65536 ) ;

        1 Reply Last reply
        0
        • A Affan Toor

          Hi! i want to generate a 16 bit license key for my product, but have no idea how to do it? Each bit of number will refer to a feature of product. can any body tell me how can i achieve this task? i have no idea from where to start and what to do....please help..!!! Thanks in advance... Regards, Affan Ahmad Toor

          M Offline
          M Offline
          maz2331
          wrote on last edited by
          #4

          16 bits is pretty small. Are you actually looking for 16 bytes instead? IE: a key code that looks like this: D41D-8CD9-8F00-B204-E980-0998-ECF8-427E (This is a string representation of a 16-byte (128 bit) MD5 hash of an empty string with "-" characters thrown in between every 2 bytes. The underlying value is: 0xD41D8CD98F00B204E9800998ECF8427E Of course, this is too big to be represented as any integer type, so we'll represent it as strings instead. In any event, I'd do something based on a 16-byte MD5 hash of the license number or "licensee name" or similar to generate a base "key code", then "XOR" your 16-bit "feature code" into the lowest two bytes of the hash. I'd also append a product name to the user name prior to the initial MD5 step to add some security and make each key product-specific. Or, you could use the lowest bit of each of the 16-bytes of the MD5 hash to indicate a particular "feature bit". Here's a more detailed step-by-step of the overall algorithm.... GIVEN: Licensee Name (string) GIVEN: Product Name (string) GIVEN: Feature Code (16-bit integer) First, convert licensee name to all upper or lower case, and append (concatenate) product name to either the beginning or end of the string. Let's call this the "ID_STRING". Second, take an MD5 hash of the ID_STRING and store it in an "ID_HASH_STRING". This is a 32-character "text" version of the hash, so we then convert each pair of 2 characters (such as "D4") to a binary byte (0xD4) and store it in a 16-character string. Third, split the high and low order bytes from the "Feature Code" and XOR them with the last two characters of the ID_HASH_STRING. Fourth, to really be nasty to hackers, drop the first two bytes of the ID_HASH_STRING and run an MD5 hash of the remaining 14 characters. Take the first character of this MD5 and append it as the first character of the new keycode, and append the last character of the MD5 and append it as the second character of the string. Step 4 ensures that people can't just easily change the value of the last 2 bytes to cheat on the permissions! Decoding the keycode is pretty much a straightforward reversal of the above steps. I've written a VB module to perform these functions and will soon post an article here on CodeProject containing the code and a sample demo application using it.

          1 Reply Last reply
          0
          • A Affan Toor

            Hi! i want to generate a 16 bit license key for my product, but have no idea how to do it? Each bit of number will refer to a feature of product. can any body tell me how can i achieve this task? i have no idea from where to start and what to do....please help..!!! Thanks in advance... Regards, Affan Ahmad Toor

            M Offline
            M Offline
            maz2331
            wrote on last edited by
            #5

            Take a look at my article at: http://www.codeproject.com/useritems/VB\_KeyCode.asp to do what you want here.

            A 1 Reply Last reply
            0
            • M maz2331

              Take a look at my article at: http://www.codeproject.com/useritems/VB\_KeyCode.asp to do what you want here.

              A Offline
              A Offline
              Affan Toor
              wrote on last edited by
              #6

              Hi! Thank you very much for all this help, you were rite that i wanted to generate 16 byte key instead of 16 bit. your reply and article helped me alot. Thanks again, looking forward for your help in future.... Regards, Affan Ahmad Toor ..................................... QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups