Simple random character generator using cryptographic functions.
.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