Generate all combinations from list of characters

后端 未结 1 1327
孤独总比滥情好
孤独总比滥情好 2021-01-25 17:42

I am busy implementing a lab for pen testers to create MD5 hashes from 4 letter words. I need the words to have a combination of lower and uppercase letters as well as numeric a

相关标签:
1条回答
  • 2021-01-25 18:15

    Use a list of integers that are ASCII codes for the characters you accept, to sample from it using your favorite (pseudo-)random number generator. Then convert each to its character using chr and concatenate them.

    Like

    perl -wE'$rw .= chr( 32+(int rand 126-32) ) for 1..4; say $rw'
    

    Notes

    • I use a one-liner merely for easy copy-paste testing. Write this nicely in a script, please

    • I use the sketchy rand, good for shuffling things a bit. Replace with a better one if needed

    • Glueing four (pseudo-)random numbers does not build a good distribution; even as each letter on its own does, the whole thing does not. But the four should satisfy most needs.

      If not, I think that you'd need to produce a far longer list (range of allowed chars repeated four times perhaps) and randomize it, then draw four-letter subsequences. A lot more work

    • I need to tap dance a little to produce (random-ish) integers from 32 to 126 using rand, since it takes only the end of range. Also, this takes all of them from that range, likely not what you want; so specify subranges, or specific lists that you want to draw from

    0 讨论(0)
提交回复
热议问题