Sign in to follow this  
Followers 0
Pain

Generate a unique key

18 posts in this topic

#1 ·  Posted (edited)

Some days ago I found SkinnyWhiteGuy's rijndael algorithm and I found it very interesting.

http://www.autoitscript.com/forum/index.php?showtopic=44581

My question is how do I generate a good key (256 bits) that is as unique as possible?

I found a post by arcker in same topic where he used 32 random character from a to z (all lowercase) to generate a key.

$encryptkey = ""
for $i = 1 to 32
   $encryptkey &= chr(Random(97,122,1))
Next

I do know that upper and lowercase will give totally different results.

So would the key be more unique if I use both upper- and lowercase and how about if I would add numbers too?

I also found it was possible to have other characters like space, exclamation mark etc.

Chr(Random(32,255,1)) would be pretty random I assume but it's not very easy to write something like

ý(}¯`8""ɽ|n/ðÈ1tÌólH8¸?[zµ

to decrypt it.

Da58D71de9B372A3869e582D51697BfM

is easier to write and should work as a key, if it's random or not I have no idea about, but for me it looks like it's random (for me arckers key also looks random...).

SkinnyWhiteGuy replied back to arcker and said:

Just as an aside, your key could be more "unique" by using 16 random Binary from 0 to F(15 in hex)

I didn't understand exactly how he meant but maybe someone else do.

Any example of how to make a unique key would be appreciated.

Edited by Pain

Share this post


Link to post
Share on other sites



thnx, I love you :P

Share this post


Link to post
Share on other sites

@ptrex

Thanks!!! that's what I was looking for.

Share this post


Link to post
Share on other sites

In addition, If you want to avoid objects and rely on the Windows API you can also use:

#Include <WinAPI.au3>

MsgBox(4096, "Generate Guid", _CreateGuid())

Func _CreateGuid()
    Local $Guid = DllStructCreate($tagGUID)
    
    $Result = DllCall("OLE32.DLL", "dword", "CoCreateGuid", "ptr", DllStructGetPtr($Guid))
    $Result = _WinAPI_StringFromGUID(DllStructGetPtr($Guid))
    
    Return $Result
EndFunc

Cheers! :)


--- TTFN

Share this post


Link to post
Share on other sites

FYI I did a Speed/Stress test to compare the Speeds of Windows API verses the the Scriptlet.TypeLib method and came up with these results:

  • Windows API = 934.094696392977 ms
  • Scriptlet.TypeLib = 9680.83178169292 ms

The Windows API was actually 10.36 times faster on my system. :)

I was surprised about the large disparity actually. Sure, I expected the API to be faster but not this fast.

I altered my tests to see how creating the TypeLib object and opening the DLL reference prior to the loops effects the results.

  • Windows API = 896.096012202668 ms
  • Scriptlet.TypeLib = 97.131898048495 ms
Interesting... Windows API only gained a minor improvement. However the TypeLib object's improvement was so astounding that it is now 97.13 times faster than the Windows API calls.

So at this point... it's all in how you want to code your project. Speed or Memory Footprint.

Code I used to test...

#Include <WinAPI.au3>

Const $MaxTest = 10000
Dim $TypeLib = ObjCreate("Scriptlet.TypeLib")

Dim $i = 0, _
    $Start = 0, _
    $Results_API, _
    $Results_Obj

MsgBox(4096, "Generate Guid", _CreateGuid())

;## Stress Test WinAPI
    $Start = TimerInit()
    $OLE32 = DllOpen("OLE32.DLL")
    For $i = 1 to $MaxTest
        _CreateGuid($OLE32)
    Next
    DllClose($OLE32)
    $Results_API = TimerDiff($Start)
    
;## Stress Test Object
    $Start = TimerInit()
    Dim $TypeLib = ObjCreate("Scriptlet.TypeLib")
    For $i = 1 to $MaxTest
        _CreateGuid2()
    Next
    $TypeLib = 0
    $Results_Obj = TimerDiff($Start)

;## And the results
    ConsoleWrite( _
        "Windows API        = " & $Results_API & " ms" & @CRLF & _
        "Scriptlet.TypeLib  = " & $Results_Obj & " ms" & @CRLF _
    )
    
Func _CreateGuid($DLL = "")
    Local $Guid = DllStructCreate($tagGUID)
    
    $Result = DllCall($DLL, "dword", "CoCreateGuid", "ptr", DllStructGetPtr($Guid))
    $Result = _WinAPI_StringFromGUID(DllStructGetPtr($Guid))
    
    Return $Result
EndFunc

Func _CreateGuid2()
    ;$TypeLib = ObjCreate("Scriptlet.TypeLib")
    $strGUID = $TypeLib.Guid
    Return $strGUID
EndFunc

--- TTFN

Share this post


Link to post
Share on other sites

Can I just say that the word 'unique' means there's only one of something? Nothing can be 'more unique' - something's either unique or it isn't. Sorry for the mini-rant but this one drives me crazy.... :)

Share this post


Link to post
Share on other sites

GUIDs aren't really unique. But creating the same number twice happens really rarely (i think till now, this didn't happen)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

GUIDs aren't really unique. But creating the same number twice happens really rarely (i think till now, this didn't happen)

"GUID" is an acronym for Globally Unique IDentifier. So, yell at the guy who coined the acronym as he obviously has no background in statistics.

Thanks Wikipedia

FYI: This is my lame attempt at humor


--- TTFN

Share this post


Link to post
Share on other sites

pain is gone .. ok but as you are reading this topic -->

i suppose i give you a little help with that:

what makes a code or numer unique is the order of possible vallues a place in the code can take.

like you have a code that is 4 terms long like : 1234 or 5555 or 0003 and you only can take numbers from 0 to 5 you will have 5 options on the first spot, 5 on the nextand another 5 options on the last spot. That makes 6*6*6*6 posibble codes ( = 6^4 )

so if you are using only letters (like a , b , c ... z ) that makes you wich the basis on 6^4 and gives 26^4

the results are ranging from aaaa to zzzz

ok now the result : if the couple of singel parts i can mix or choose for each place is bigger the more possible combinations i can make. Some possible system you could take as basis.

short list:

binary : 0 or 1

just numbers: 0 1 2 3 4 5 6 7 8 9

from aboth HEX ( btw 16 not 15 ): 0 1 2 3 4 5 6 7 8 9 A B C D E F e.g.: 47c85c could be a funny green in html

just letters: a b c d .... x y z

etc etc

Share this post


Link to post
Share on other sites

Thanks I already got the answer I was looking for some time ago but thanks anyways.

Share this post


Link to post
Share on other sites

"GUID" is an acronym for Globally Unique IDentifier. So, yell at the guy who coined the acronym as he obviously has no background in statistics.

Thanks Wikipedia

FYI: This is my lame attempt at humor

Someone I know attended a seminar on some MS Programming subject. The lecturer had a PC running in the background all the time with this scroll going up the screen. When asked about it the lecturer said "Oh that! It just generates GUIDs 24/7. I'm trying to use them all up so MS will be screwed!!" :)

Share this post


Link to post
Share on other sites

lol can you say.. OWNED although from what you say... depending on the AMOUNT of digits, it could be limitless

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Some time ago (about the same time as when this topic was created) I made some research about GUID's. It looks like I finally got some use of that research now. :)

@MilesAhead

Good luck, you got 340,282,366,920,938,463,463,374,607,431,768,211,456 possible combinations for a GUID, and that's only 32 chars. (Same as a 128-bit password)

To make it easier to understand this number there is:

6,740,000,000 human inhabitants as of November 2008 on Earth.

7,500,000,000,000,000,000 sand grains on Earth.

43,252,003,274,489,856,000 possible combinations on a Rubik's Cube.

7,000,000,000,000,000,000,000,000,000 atoms in a human body.

As you can see this is still nothing compared to the GUID's.

(340,282,366,920,938,463,463,374,607,431,768,211,456)

Let's say you want to generate all possible combinations and you can generate 1,000,000,000,000 combinations every nanosecond (one billionth of a second) it would still take 1,000,000,000 years for you.

Now in the reality it's not possible to generate that many combinations.

But let's say you got the worlds fastest super computer, the IMB Roadrunner, the result would look like this:

3.4 x 10^38 (combinations)

-------------------------- ~ 3.4 × 10^23 seconds

1 x 10^15 (1 petaflop, one quadrillion floating point operations per second. Your computer can execute approximately 50-200 million floating point operations per second depending on the hardware.)

3.4 × 10^23

------------ ~ 1.07739499 × 10^16 years

31557600 (sec on a average year with 365.25 days)

1.07739499 × 10^16 = 10,773,949,900,000,000 years

That's 10 quadrillion years. (or billiard if you live in EU)

The amount of space to store all these GUID's would be insane....

Edited by Pain

Share this post


Link to post
Share on other sites

like i said inifite lol(close enough to be called infinet)

Share this post


Link to post
Share on other sites

Some time ago (about the same time as when this topic was created) I made some research about GUID's. It looks like I finally got some use of that research now. :)

@MilesAhead

Good luck, you got 340,282,366,920,938,463,463,374,607,431,768,211,456 possible combinations for a GUID, and that's only 32 chars. (Same as a 128-bit password)

To make it easier to understand this number there is:

6,740,000,000 human inhabitants as of November 2008 on Earth.

7,500,000,000,000,000,000 sand grains on Earth.

43,252,003,274,489,856,000 possible combinations on a Rubik's Cube.

7,000,000,000,000,000,000,000,000,000 atoms in a human body.

As you can see this is still nothing compared to the GUID's.

(340,282,366,920,938,463,463,374,607,431,768,211,456)

Let's say you want to generate all possible combinations and you can generate 1,000,000,000,000 combinations every nanosecond (one billionth of a second) it would still take 1,000,000,000 years for you.

Now in the reality it's not possible to generate that many combinations.

But let's say you got the worlds fastest super computer, the IMB Roadrunner, the result would look like this:

3.4 x 10^38 (combinations)

-------------------------- ~ 3.4 × 10^23 seconds

1 x 10^15 (1 petaflop, one quadrillion floating point operations per second. Your computer can execute approximately 50-200 million floating point operations per second depending on the hardware.)

3.4 × 10^23

------------ ~ 1.07739499 × 10^16 years

31557600 (sec on a average year with 365.25 days)

1.07739499 × 10^16 = 10,773,949,900,000,000 years

That's 10 quadrillion years. (or billiard if you live in EU)

The amount of space to store all these GUID's would be insane....

Ah, I think they guy was doing it for a joke.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

the problem with randomized is that you don't really have to generate all the possibilities .. you just have to generate the same one twice!

p.s: maybee you could do it with Blue Gene/Q :)

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

I know, but still if you generate 1,000,000,000 GUID's every sec for 100 years (24/7) it's still only 50% chance that you have generated the same GUID.

So well I think we can say that a GUID is pretty unique.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0