Author Topic: Function to create random strings  (Read 1003 times)

nidud

  • Member
  • *****
  • Posts: 2049
    • https://github.com/nidud/asmc
Re: Function to create random strings
« Reply #15 on: October 30, 2020, 04:41:16 AM »
Here's one using RDRAND.
Code: [Select]

    .686
    .xmm
    .model flat, c

    option dllimport:<msvcrt>
    printf proto :ptr, :vararg
    exit   proto :dword

    .code

__randc proc

    rdrand eax
    .while al > 'z' || \
           al < '0' || \
           al >= ':' && al <= '>' || \
           al >= '[' && al <= '`' && al != '_'
        rdrand eax
    .endw
    ret

__randc endp

__rands proc uses edi b:ptr sbyte, count:dword

    mov edi,b
    .while count
        __randc()
        stosb
        dec count
    .endw
    mov byte ptr [edi],0
    mov eax,b
    ret

__rands endp

main proc

  local i:byte, string[128]:sbyte

    .for i = 0 : i < 16: i++

        printf("%s\n", __rands(&string, 64))
    .endf
    exit(0)

main endp

    end main

gf?P0SfJP@Es_MZ0cL66omo7lXXyNu_o8kVy@s2a7ml75zNPje35jHTTHhtOXKRK
wwKUUE@XIxpCPk49d9ERd?bepYG@sPfl7HhKVhVJQJGeLw28kGMmyPTHJhLGII1S
miNDRY54jRXKwQSUtQ6p4oLJQM5Lu4H9FmZYdjldpwyu_M8EC8UyyQECv83ckj_I
Ajo9RT3S0LNxSpzOGD?DSiE03X?cnS6?bFLN_D2xSPe?hx3DFVi9U3dwxZGGnLWI
5q_ZZoNUqqLQ7c?RPf6nWlS7reo0YYv9HPzT_vKoWTJF?PlsbZESR5N0EdB7X0ra
ctQ1iX2_K2fIMO0cSAKmcYuZ3ibqqyLlQELnV3r9UG0L1Ytzv?zcvl6EMGZxB0kJ
dWh?F3fHX3wNrs@hH4blpA6fr_QJjVHf9M3iqp6qcmLeJKeHSxPck?23sAxBZj?U
U8@IWHmCNi4lpbqLS9l07E55QZG?thDB3DpLAqfM2@6AvSrwT2odcrGaPhkWlF0G
F55eEK0ry5PWIgO9XPWbJ5Fh6tFZ6y8jUmNnCmmXBQTG4Rrava35d8JaLLT0qody
RbwPq@C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