NO

Author Topic: String with random characters  (Read 1790 times)

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
String with random characters
« on: July 02, 2024, 09:02:13 PM »
Simple random character generator using cryptographic functions.

Code: [Select]
.386
.model flat,stdcall
option casemap:none

include RandString.inc

.data?

buffer      db 64 dup(?)

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi edi ebx

LOCAL counter:DWORD

    invoke  RandomBytes,64,ADDR buffer

    mov     esi,OFFSET buffer
    mov     edi,26
    mov     counter,64
    mov     ebx,1
@@:
    movzx   eax,BYTE PTR [esi]
    xor     edx,edx
    div     edi
    and     eax,ebx
    shl     eax,5
    lea     edx,[edx+eax+65]
    mov     BYTE PTR [esi],dl
    add     esi,ebx 
    sub     counter,ebx
    jnz     @b
    invoke  printf,ADDR buffer
    ret

main ENDP

RandomBytes PROC dwLength:DWORD,pBuffer:DWORD

LOCAL hProvider:DWORD

    xor     eax,eax
    invoke  CryptAcquireContext,ADDR hProvider,eax,eax,\
            PROV_RSA_FULL,CRYPT_VERIFYCONTEXT or CRYPT_SILENT
    invoke  CryptGenRandom,hProvider,dwLength,pBuffer
    invoke  CryptReleaseContext,hProvider,0
    ret

RandomBytes ENDP

END start
Code it... That's all...