Page 1 of 1

random keygen

Posted: Fri Aug 30, 2013 10:31 pm
by Nubeat7
after some research i found this code:

Code: Select all

(0..@lenght).to_a.map{|a| rand(16).to_s(16)}.join

to generate random keys like are used for serial or product keys...
i simply run a loop and save it in an array, like this my computer is able to generate up to 30 000 keys (ruby module turns off with 50 000...

it would be useful to provide a list of pruduct keys for purchasing custumors of your software product(to get updates with the key) or maybe also for a simple protection system...

my question now is, are the generated numbers unique in this code?

how to bulid a guid / uuid keygen? found some codes about "SecureRandom" can this be used in FS?

some link about: http://stackoverflow.com/questions/1117 ... ds-in-ruby

Re: random keygen

Posted: Sat Aug 31, 2013 1:35 am
by Tronic
if you do not have to use it to the plugins (because now they can no longer recall, external extensions)
it can be created using Win32API.
only with the ruby is not effectively secure and unique.

Code: Select all

require 'Win32API'
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa379205(v=vs.85).aspx
@api = Win32API.new('rpcrt4', 'UuidCreate', 'P', 'L')

buffer = ' ' * 16
@api.call(buffer)

a, b, c, d, e, f, g, h = buffer.unpack('SSSSSSSS')
uuid = a, b, c, d, e, f, g, h  # => [33474, 814, 35932, 17755, 31113, 32122, 12955, 9560]

Re: random keygen

Posted: Sun Sep 01, 2013 1:41 pm
by Nubeat7
thanks tronic, but looks like this one has just 5 digits and only numbers so i think its not very secure with 100 000 possibilities, i really dont get how this is working how should a 5 digit number be universal unique? here i also tried another library but with the same effect, or is every letter in your example one part of the uuid?

Code: Select all

    require 'Win32API'
    @api = Win32API.new('ole32', 'CoCreateGuid', 'P', 'S')
    buffer = ' ' * 16
    @api.call(buffer)
    uuid = buffer.unpack('SSSSSSSS')


if so how can i get it in a format with letters too like these classic serials like jK39-o7U2-287b-kjh5 with 0..9, A..Z, a..z included

like the example in my first post but i don`t know if keys are repeating with this code?
i mean when i use

Code: Select all

output p.uniq 
instead of

Code: Select all

output p
all the generated key are unique, what doesnt mean that they are universal unique identifiers?