Snippet name: Random string generator
Keywords: String, Pseudo random, Generator
Description: generate a random string at a given length
Compiler/os/bit: MASM, windows, 32 (or 64... I dunno)
Code:
Code:
.386
.model flat, stdcall
option casemap: none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
.data
szTable db "ejiotio346juiuiotyuituiogrhjior4rhy789te5u90tuihnjfioghuigfjio2058989fjisefhioDJIAGFUHSDIFRUHOAHFVHDIOASJFOigodtghogjdfnfjkosbhjfhd",0
buffer db 9 dup(0)
capt db "SCHiM",0
.code
Rand proc ; Start of our random number function
start:
invoke GetTickCount ; we do some random operations on the registers here until...
div eax ; devide eax
mov edx, sizeof szTable ; move the size of our
ror eax, 03h ; rotate 3*16^0 (3 :P) to the right
xor eax, ebx ; xor eax, with ebx
rol eax, 013h ; rotate to the left (3*16^0 + 1*16^1 + 0) 19 :P
xor eax, ebx ; xor eax with ebx
mov esi, eax ; move eax to esi
invoke GetTickCount ; get tick count once more
mov edx, sizeof szTable ; move the siz of our table once more, because gtc uses edx
xor eax, esi ; here... (and xor eax with esi)
comp:
.if eax < edx
ret ; if the number is good, return
.else
sub eax, sizeof szTable ; if the number is too big, decrease it's size
jmp comp
.endif
Rand endp ; end of our random number function
main proc
xor ebx, ebx
rar:
call Rand ; random number is stored in eax
mov al, [szTable + eax] ; put a random character in al
mov [buffer + ebx], al ; put the character in our buffer at the location of ebx
inc ebx ; increment our counter (I know ebx is not a counter register, but who cares... :P
cmp ebx, 8d ; compare our counter with 8 in decimal
jne rar ; if they don't match put another random char back in our buffer
invoke MessageBoxA,0, addr buffer, addr capt, MB_OK ; if they match, show the result to the user
ret
main endp
end main
This'd be a ASM speed freaks worst nightmare, but I don't care

because this works for me, I hope it will for others