Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .686p
- .model flat, stdcall
- .stack 4096
- ExitProcess PROTO, dwExitCode : DWORD
- include Irvine32.inc
- .data
- passPrompt BYTE "Please Enter Your Passcode: ", 0
- successPrompt BYTE "Door is now open", 0
- failPrompt BYTE "Intruder or new resident", 0
- useNewPrompt BYTE "Would you like to use this code for another apartment? (Y/N) ", 0
- dontSetPrompt BYTE "Well then get off my lawn!", 0
- apartmentPrompt BYTE "Please Enter the Apartment Number: ", 0
- apartErrorPrompt BYTE "ERROR: Invalid apartment number entered. ", 0
- apartSuccessPrompt BYTE "Successfully updated passcode: ", 0
- currentCodesPrompt BYTE "Current Codes: ", 0
- err_msg BYTE "ERROR: Invalid input!", 0
- comma BYTE ", ", 0
- numOfApts = 17
- codeArr WORD numOfApts DUP(?) ; will be filled later
- .code
- FindCode PROTO inkey:WORD
- main PROC
- ; fill array with default values
- push OFFSET codeArr
- push numOfApts
- call FillPasscodes
- mov edx, OFFSET currentCodesPrompt
- call WriteString
- call CRLF
- call PrintArray ; Show the array so people can
- mov edx, OFFSET passPrompt
- call WriteString ; prompt the user for passcode
- call ReadDec
- call CRLF
- jc INPUT_ERROR ; If CF = 1, error in input
- .IF ax > 999 && ax < 9999
- INVOKE FindCode, ax
- .ELSE
- jmp INPUT_ERROR
- .ENDIF
- .IF edx == 1
- mov edx, OFFSET successPrompt
- call WriteString
- call CRLF
- INVOKE ExitProcess, 0
- .ELSE
- mov edx, OFFSET failPrompt
- call WriteString
- call CRLF
- push ax ; Push their entered passcode for later use
- jmp AskNewCode
- .ENDIF
- INPUT_ERROR: ; The program has experienced an error
- mov edx, OFFSET err_msg
- call WriteString
- call CRLF
- INVOKE ExitProcess, 1
- AskNewCode:
- ; This only works before Windows XP...
- mov eax, 10000
- INVOKE Delay ; Pause for 10 seconds
- mov edx, OFFSET useNewPrompt
- call WriteString
- call ReadChar
- call CRLF
- .IF al == 89 || al == 121 ; 'y' or 'Y'
- jmp SetNewCode
- .ELSE
- mov edx, OFFSET dontSetPrompt
- call WriteString
- call CRLF
- INVOKE ExitProcess, 0
- .ENDIF
- SetNewCode:
- mov edx, OFFSET apartmentPrompt
- call WriteString
- call ReadDec
- call CRLF
- jc INPUT_ERROR
- .IF ax < 1 || ax > 17
- mov edx, OFFSET apartErrorPrompt
- call WriteString
- call CRLF
- INVOKE ExitProcess, 1
- .ELSE
- pop bx
- call SetCode
- mov edx, OFFSET apartSuccessPrompt
- call WriteString
- call PrintArray
- .ENDIF
- INVOKE ExitProcess, 0
- main ENDP
- SetCode PROC
- mov esi, OFFSET codeArr
- mov ecx, 2
- mul ecx ; EAX = EAX * the size of a word (2)
- add esi, eax ; go to the appropriate array index
- mov [esi], bx ; set the code entered into the appropriate place
- ret
- SetCode ENDP
- ;----------------------------------------
- ; Find the given key in the codeArr
- ; RETURNS: 1 if found, 0 if not found
- ;----------------------------------------
- FindCode PROC, inkey:WORD
- mov esi, OFFSET codeArr
- mov ecx, LENGTHOF codeArr
- mov ax, inkey
- Search:
- cmp ax, [esi]
- JZ Found
- add esi, TYPE codeArr
- LOOP Search
- mov edx, 0 ; Not found (0)
- ret
- Found:
- mov edx, 1 ; Found (1)
- ret
- FindCode ENDP
- ;--------------------------------------------------------
- ; Fills the codeArr array with random 4-digit integers
- ; to be used as the default passcodes
- ;--------------------------------------------------------
- FillPasscodes PROC
- push ebp
- mov ebp, esp
- mov esi, [ebp+12] ; get the array offset
- mov ecx, [ebp+8] ; get the size of the array
- call Randomize
- FillLoop:
- mov eax, 4000 ; Top range or random number generation
- call RandomRange
- mov ebx, eax
- mov eax, 4000
- call RandomRange
- add ebx, eax
- add ebx, 1000 ; make sure numbers are at least above 1000
- mov [esi], ebx
- add esi, TYPE codeArr
- loop FillLoop
- pop ebp
- ret
- FillPasscodes ENDP
- ;---------------------------
- ; Print the codeArr array
- ;---------------------------
- PrintArray PROC
- mov esi, OFFSET codeArr
- mov ecx, LENGTHOF codeArr
- mov edx, OFFSET comma
- mov eax, 0
- L1:
- mov ax, [esi]
- call WriteDec
- call WriteString
- add esi, TYPE codeArr
- loop L1
- call CRLF
- ret
- PrintArray ENDP
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement