engineering ethics

Topics: Randomness, Random password generator, Hardware random number generator Pages: 6 (643 words) Published: December 17, 2013

Genrate 7 letters password
; Example3.asm: A Simple Random Password Generator (7 characters)

.386
.model flat, STDCALL

; INCLUDE FILES
include        \masm32\include\kernel32.inc
include        \masm32\include\windows.inc
include         \masm32\include\user32.inc
include         getseg.inc  ; Our include file

; LIBRARY
includelib    \masm32\lib\kernel32.lib
includelib      \masm32\lib\user32.lib
includelib      getseg.lib  ; Our include file

; random number generating function
Random PROTO :DWORD,:DWORD

.data
msg_caption     db "Random password generator",0
my_data         db "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:"                 db "t:u:v:w:x:y:z:A:B:C:D:E:F:G:H:I:J:K:L:"                 db "M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:0:1:2:3:4:"                 db "5:6:7:8:9",0  

out_data        db 123 dup(0) ;
pass_out        db 123 dup(0) ;
ctr             dd 0    ;

.code
start:
Passloop:

invoke Random, 1,62                                     ; random number generator function invoke GetSegStr, ADDR my_data, eax, ":", ADDR out_data ; get a random character from the table invoke lstrcat, ADDR pass_out, ADDR out_data            ; add character to pass_out invoke Sleep, 10 ; for random numgen function (GetTickCount) add ctr, 1       ; increment loop counter

cmp ctr, 7       ; does pass_out contain 7 characters already? jne Passloop     ; nah, add some more random character
Done:

; Display randomly generated password
invoke MessageBox, NULL, ADDR pass_out, ADDR msg_caption, MB_OK

; got this random number generator function from some masm board posting

Random PROC first:DWORD,second:DWORD
LOCAL rand:DWORD

invoke GetTickCount
mov rand, eax

mov ebx,second
sub ebx,first
inc ebx
xor edx,edx
mov eax,rand
div ebx
add rand,eax
add edx,first
mov eax,edx
ret

Random ENDP

invoke ExitProcess,0
end start

Check Validity of Password
.386
.model flat,stdcall
option casemap:none

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
cr      equ 0dh
lf      equ 0ah
byteswrote      dd 0
hstdo           dd 0
hstdi           dd 0
ok_txt           db 'Password is OK!',0
Info_txt        db 'Please Input your password:',0
error_txt       db 'The length of password should in this scope(6~12 chars)!',cr,lf,0 error2_txt      db 'The first character should be a letter!',cr,lf,0 error3_txt      db 'The other character should be a letter or numeric!',cr,lf,0 password        db  16 dup(0)  ;include cr,lf,0

.code
start:
        call    GetSHandle
        lea     ebx,Info_txt
        call    WriteString
        call    GetPassword
        push    0
        call    ExitProcess

GetSHandle proc
        push    STD_OUTPUT_HANDLE
        call    GetStdHandle
        mov     [hstdo],eax            
        push    STD_INPUT_HANDLE
        call    GetStdHandle
        mov     [hstdi],eax
        ret
GetSHandle endp

WriteString proc
        pushad
        mov     edi,ebx
        xor     eax,eax
        mov     ecx,0fffh
        cld
sc_loop:        
        scasb                                ; find end of string         jz      fnd
        loop sc_loop
fnd:    
        mov     ecx,edi              
        sub     ecx,ebx
        push    0
        push    offset byteswrote
        push    ecx    
        push    ebx
        push    [hstdo]
        call    WriteConsole
        popad
        ret
WriteString endp

GetPassword proc      
        pushad
        lea edi, password
        xor eax,eax
        stosb
        dec edi
        push 0                      ;lpReserved         push offset byteswrote      ;lpNumberofCharsRead         push 15                     ;nNumberOfCharsToRead         push edi                    ;lpBuffer

        push [hstdi]              ...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay about Ethics and Engineering
  • The Ethics of Engineering Essay
  • Ethics Essay
  • Essay on Genetic Engineering ethics
  • Essay about Mechanical Engineering
  • Engineering and Metaphor Essay
  • Engineering and Qatar Exxon Mobil Essay
  • Essay about Fluor's Global Engineering Serveice

Become a StudyMode Member

Sign Up - It's Free