#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0

    Byte of hashcode


    Hi, lets say i have md5sum like "d41d8cd98f00b204e9800998ecf8427e" and I want to generate 256 numbers in random sequence from range 0 to 255 using this md5sum.

    Any idea how to deal with it ?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    The simplest method would be to, say, break the hash into four parts of 8 digits, convert each part into a number (hex->dec), XOR them together, and use the result as an RNG seed.

    But do you need something cryptographically secure? Reproducible on different machines? Can you use the original input to MD5 instead? Any constraints?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    The simplest method would be to, say, break the hash into four parts of 8 digits, convert each part into a number (hex->dec), XOR them together, and use the result as an RNG seed.

    But do you need something cryptographically secure? Reproducible on different machines? Can you use the original input to MD5 instead? Any constraints?
    Yes, I need to make it reproducible.

    For example, it's like that:
    1. USER INPUT: "MIKE" (can be different with 1 char, or 120 chars - I need to md5 it)
    2. "MIKE" to MD5
    3. Generate reproducible random sequence of numbers from 0-255 using this md5sum

    How do you think about my idea, but I am not sure is it good at all:
    Let's take string "MIKE" as user input (key).

    "MIKE" in md5 is "94f4a1c41b8358205fdc712dd5f12dc8".
    It's 32 digits and I need to get 256 numbers (0-255).
    256/32=8, so I seperate my md5sum in 8 groups for 4 chars (32/8=4) and i get: "94f4a1c4 1b835820 5fdc712d d5f12dc8c"
    Now I md5 each of group i got before (g? is variable just for help):
    g1 = md5("94f4a1c4") = "23567aa89eae688c3a6f02d07b2beeeb"
    g2 = md5("1b835820") = "499a930d757a1ad7e6b983d532e2fb1a"
    g3 = md5("5fdc712d") = "761fb78a69470de96155e89df6990a8d"
    g4 = md5("d5f12dc8c") = "24d1f27c5fecff6f731794bfd32e72d9"
    And again I seperate each group I got to 8 groups of 4 chars.
    .
    .
    .
    And i am doing it until I get 256 groups of 8 chars.
    But does it make any sense ? I think its not reproducible and anyway i would have to get somehow only 1 number from this from this 8 chars group and i don't have an idea how to



    How to deal with it ?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    If you only need something that seems random then you probably could get away with just rehashing the data. Although simply rehashing the previous hash (not the broken up pieces) is simpler.

    By the way, what is this for?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    If you only need something that seems random then you probably could get away with just rehashing the data. Although simply rehashing the previous hash (not the broken up pieces) is simpler.

    By the way, what is this for?

    What do you mean to rehash the data ?

    Do you mean do it like that (?):

    md5("MIKE") = "94f4a1c41b8358205fdc712dd5f12dc8"

    md5("94f4a1c41b8358205fdc712dd5f12dc8") = "e3e1ff3d938a5cece2cfaecb231f4ab5"

    md5("e3e1ff3d938a5cece2cfaecb231f4ab5") = "f7ec1e24382d9dfe9b1a6028d0fba3f6"

    md5("f7ec1e24382d9dfe9b1a6028d0fba3f6") = "aaebc56f98dc31501c92c23f1b27db36"

    md5("aaebc56f98dc31501c92c23f1b27db36") = "a7871acf8a406e8abe706a8363742b35"

    And what about that ? I think it's a good idea but I don't understand it yet enough, I think Do you mean i should generate each number from each md5sum and make md5 sum 256 times ? But how to get 1 digit from 32-digit md5sum and keep it reproducible ?



    It's part of my project at IT studies. I got an obligation to use it by hashing a key.
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    You still break a hash into four to get your numbers. I'm just saying you don't then have to use the hash of each of those parts to get the next hash - just hash the string you got.

    Code:
    MIKE => 94f4a1c4 1b835820 5fdc712d d5f12dc8
            1        2        3        4
    
    94f4a1c41b8358205fdc712dd5f12dc8 => e3e1ff3d 938a5cec e2cfaecb 231f4ab5
                                        5        6        7        8
    
    e3e1ff3d938a5cece2cfaecb231f4ab5 => f7ec1e24 382d9dfe 9b1a6028 d0fba3f6
                                        9        10       11       12
    
    f7ec1e24382d9dfe9b1a6028d0fba3f6 => aaebc56f 98dc3150 1c92c23f 1b27db36
                                        13       14       15       16
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    You still break a hash into four to get your numbers. I'm just saying you don't then have to use the hash of each of those parts to get the next hash - just hash the string you got.

    Code:
    MIKE => 94f4a1c4 1b835820 5fdc712d d5f12dc8
            1        2        3        4
    
    94f4a1c41b8358205fdc712dd5f12dc8 => e3e1ff3d 938a5cec e2cfaecb 231f4ab5
                                        5        6        7        8
    
    e3e1ff3d938a5cece2cfaecb231f4ab5 => f7ec1e24 382d9dfe 9b1a6028 d0fba3f6
                                        9        10       11       12
    
    f7ec1e24382d9dfe9b1a6028d0fba3f6 => aaebc56f 98dc3150 1c92c23f 1b27db36
                                        13       14       15       16

    Ok, I see it now but do you have any good idea to make digit (0-255) from "94f4a1c4" ?

    What do you think about changing each char from "94f4a1c4" to ascii, multiple it and modulo it by 256, like..

    ascii('9') * ascii('4') * ascii('f') * ascii('4') * ascii('a') * ascii('1') * ascii('c') * ascii('4') % 256

    What do you think about that ? Is there better idea ?

    Well I am not sure but the problem here may be that it can happen i won't get all numbers from 0-255 and there may be some numbers missing and program will hang in loop.
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    The value being returned by your md5 function is represented in hex (ie base 16). To get a number from 0 - 255, all you have to do is break the hash into 1-byte chunks and convert each chunk from base 16 to base 10.

    94 f4 a1 etc.

    You would chunk it into 4-byte chunks if you were trying to get full 32-bit integers out of it.

    Alternatively, if you can change your md5 hash function to return the raw bits instead of the hex string representation that might save you the trouble of having to convert from base 16.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by E-Oreo
    The value being returned by your md5 function is represented in hex (ie base 16). To get a number from 0 - 255, all you have to do is break the hash into 1-byte chunks and convert each chunk from base 16 to base 10.

    [...]

    You would chunk it into 4-byte chunks if you were trying to get full 32-bit integers out of it.

    Alternatively, if you can change your md5 hash function to return the raw bits instead of the hex string representation that might save you the trouble of having to convert from base 16.
    Well, but if I convert "94f4a1c4" to:
    94 = 148
    f4 = 244
    a1 = 161
    c4 = 196


    And how should I act with that decimal numbers ? Multiple them and modulo 256 ? Or use them as my individual decimal to my set of 0-255 decimal numbers ?

    There is another problem, becouse what if there will be some numbers from 0-255 missing and i wont able to get them with next and next md5 of previous md5 ?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    191
    Rep Power
    50
    @rek3x,

    I have a feeling, that you didn't communicate well, what you are trying to do.

    I'm going to make a guess:

    A. To generate a sequence including every integer from 0 to 255 inclusive, with each integer appearing exactly once. [This can be described as permutation of the elements of Z_256.]

    B. For the ordering of the sequence to be determined from an MD5 hash in such a way that every distinct MD5 hash will result in a distinct ordering.

    Are we getting warmer?
    Last edited by mah$us; April 1st, 2013 at 05:21 PM.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by mah$us
    @rek3x,

    I have a feeling, that you didn't communicate well, what you are trying to do.

    I'm going to make a guess:

    A. To generate a sequence including every integer from 0 to 255 inclusive, with each integer appearing exactly once. [This can be described as permutation of the elements of Z_256.]

    B. For the ordering of the sequence to be determined from and MD5 hash in such a way that every distinct MD5 hash will result in a distinct ordering.

    Are we getting warmer?
    A. (with reproducible order of this permutation when using same key)

IMN logo majestic logo threadwatch logo seochat tools logo