Can i use MD5(String)+SHA1(String) for uniqueid? (ASCII Only)

Mihai

i tried this piece of code

For i=1 to 1000000
mystring.s=Str(i)+"'2013-"+mm+"-"+dd+"','"+valoare+"','"+curs+"','"+total+"','"+Str(cont)+"','"+simbolcont+"','Denumire"+Str(i)+"','"+valuta.s+"','"+RSet(Str(i),40,"0")+"','"+total.s+"'"
id.s=UCase(MD5Fingerprint(@mystring.s,StringByteLength(mystring))+SHA1Fingerprint(@mystring,StringByteLength(mystring)))
Next i

the code above is in Purebasic, but i am more intrested in the principle of using this for uniqueid i can say that in 1,000,000 generated strings i did not found any collisions

MD5(String)+SHA1(String) resulting a 72 characters string for uniqueid?

Keep in mind that String is the same in both functions and variyng length 300-350 chars

or the simple question

if a SHA1 collide does a MD5 of same string collide too? or viceversa? i'm not a math genius, but i guess the colliding factor is low..

i can not use uniqueid based on timestamp here.

Thank you for your time.

Mihai

To answer my own question quote from other forum

If I have two random strings (s1, s2) that are different (s1 != s2), you want to know the probability that md5(s1) == md5(s2) AND sha1(s1) == sha1(s2).

Well, first for two specific randomly chosen strings what is the probability that md5(s1) == md5(s2)? Answer its 1/2^128 as the first hash is some 128-bit string, and the chances that the second hash equals the second is 1 in 2^128 or about 2.9 x 10^-37 %.

Similarly, P(sha1(s1) == sha1(s2)) = 2^-160 ~ 6.8 x 10^-47 %.

Now the probability that that both conditions would be true assuming they are independent conditions (that is that the hashing functions are fundamentally independent of each other), is found by multiplying the probabilities since P(X AND Y) = P(X) P(Y) so P(md5(s1)==md5(s2) AND sha1(s1) == sha1(s2)) = 2^-288 ~ 2 x 10^-85 %.

Granted we assumed the hashing functions act independent of each other on the string -- which is a fair assumption for md5 and sha1 as hashing functions. But if instead of comparing MD5 and SHA-1, we compared MD5 and a new hashing function that's just MD5 applied to itself 100 times, we would find that whenever md5(s1) == md5(s2), that we'd also have md5^100(s1) == md5^100(s2), so the probability of both colliding is the same as the probability of having one collision.

Similarly, if we had a silly "hash" function that was just silly_hash(s) = md5(s) ++ s (where ++ means concatenate), then you could show that if s1 != s2 and md5(s1) == md5(s2) then silly_hash(s1) != silly_hash(s2) -- meaning that you could never have a double collision with md5 and silly_hash.

If you take 2 specific strings and compare, there's a 1 in 2^288 ~ 49732323640978664215538224814682084010045615079734771744046397689315949701253337‌​5533056 chance of both matching. Granted if you generate roughly about 2^144 ~ 22300745198530623141535718272648361505980416 strings together, there's a good chance that both hashes will match for one.

Tested with 3,500,000 strings and not a match .. then it's good enough for me (for the db i use to have that much records it requires about 10+ years of input at the rate they input (1.400.000 records in 4 years) - and i did a idcheck on the way (and they can modify if needed 1 char somewhere))
And 22300745198530623141535718272648361505980416? i cant even count that.
Hope it helps someone. The answer is Yes i can use MD5(s1)+SHA1(s1) as id.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i use malayalam ASCII fonts?

From Dev

Can I match against a string that contains non-ASCII characters?

From Dev

How can I create large ASCII text from a string?

From Dev

How can I convert a String into ASCII and then back in Haskell?

From Dev

How can i find substring of concatenation ASCII and std::string?

From Dev

How Can i know if a string is on MD5 format

From Dev

How can I use grep to search only on the first line of files for a specific string?

From Dev

Use .filter with a uniqueId

From Dev

I can't take only a part of string

From Dev

in C# how do I convert what I think is a string of hex ascii to something i can read?

From Dev

How can I use non-ASCII characters?

From Dev

How can I use powershell to create an ascii to hex converter in batch?

From Dev

PHP - String with ASCII-Extended chars only

From Dev

Check that a string contains only ASCII characters?

From Dev

Is std::string supposed to have only Ascii characters?

From Dev

regex to contain only ascii chars on string on java

From Dev

Match if String contains only ASCII character set

From Dev

How do I convert “thm conjI” to an ASCII string I can save to a file?

From Dev

How do I convert “thm conjI” to an ASCII string I can save to a file?

From Dev

How can I use cin only once?

From Dev

Can I use Couchdb as a webserver and the only backend?

From Dev

How can I use only the views in Backbone?

From Dev

Can i use only _ (underscore) for the name of the class?

From Dev

How can I use locate only for a directory

From Dev

How Can I Use a Regex on the Reverse of a string?

From Dev

why I can't use string as id

From Dev

How can I use gzip on a string?

From Dev

Can i use "==" in a http query string?

From Dev

How can I use this string replace in MySQL

Related Related

  1. 1

    How can i use malayalam ASCII fonts?

  2. 2

    Can I match against a string that contains non-ASCII characters?

  3. 3

    How can I create large ASCII text from a string?

  4. 4

    How can I convert a String into ASCII and then back in Haskell?

  5. 5

    How can i find substring of concatenation ASCII and std::string?

  6. 6

    How Can i know if a string is on MD5 format

  7. 7

    How can I use grep to search only on the first line of files for a specific string?

  8. 8

    Use .filter with a uniqueId

  9. 9

    I can't take only a part of string

  10. 10

    in C# how do I convert what I think is a string of hex ascii to something i can read?

  11. 11

    How can I use non-ASCII characters?

  12. 12

    How can I use powershell to create an ascii to hex converter in batch?

  13. 13

    PHP - String with ASCII-Extended chars only

  14. 14

    Check that a string contains only ASCII characters?

  15. 15

    Is std::string supposed to have only Ascii characters?

  16. 16

    regex to contain only ascii chars on string on java

  17. 17

    Match if String contains only ASCII character set

  18. 18

    How do I convert “thm conjI” to an ASCII string I can save to a file?

  19. 19

    How do I convert “thm conjI” to an ASCII string I can save to a file?

  20. 20

    How can I use cin only once?

  21. 21

    Can I use Couchdb as a webserver and the only backend?

  22. 22

    How can I use only the views in Backbone?

  23. 23

    Can i use only _ (underscore) for the name of the class?

  24. 24

    How can I use locate only for a directory

  25. 25

    How Can I Use a Regex on the Reverse of a string?

  26. 26

    why I can't use string as id

  27. 27

    How can I use gzip on a string?

  28. 28

    Can i use "==" in a http query string?

  29. 29

    How can I use this string replace in MySQL

HotTag

Archive