DM4BAE

by

DECLARE FUNCTION Hash# (pw$)
DECLARE FUNCTION Authorized% (c$, pw#)
DECLARE FUNCTION GetInitialPassword# (c$)
CLS : LOCATE 23, 1
CONST GameName = "DM4BAE": ' For testing
PRINT "DM4BAE-Security"
PRINT "---------------"
PRINT "This consists of 1) a driver which can be used to debug"
PRINT "the password verification functions and 2) said functions"
PRINT : PRINT
DEFSTR A-Z ' Debugging
' Facility to bypass password if user doesn't want it
DIM SHARED pwW AS STRING * 15, pwB AS STRING * 15
LSET pwW = "": LSET pwB = "": ' Fill with spaces
' Actual password is kept in a variable length string
DIM pwdString AS STRING
Test$ = "Refuse to enter a password": GOSUB StartTest
IF GetInitialPassword("White") <> 0 THEN STOP: ' Bug detected
GOSUB Passed

Test$ = "Enter a password for White other than 'White'": GOSUB StartTest
RANDOMIZE TIMER: ' To ensure this doesn't hurt anything
t# = GetInitialPassword("White")
IF t# = 0 THEN STOP: ' Bug detected
GOSUB Passed
pwdString = LTRIM$(STR$(t#)): wPass# = VAL(pwdString)

Test$ = "Enter an incorrect password for White": GOSUB StartTest
RANDOMIZE TIMER
IF Authorized("White", wPass#) THEN STOP: ' Bug detected
GOSUB Passed

Test$ = "Enter the correct password": GOSUB StartTest
RANDOMIZE TIMER
IF NOT Authorized("White", wPass#) THEN STOP: ' Bug detected
GOSUB Passed

Test$ = "Enter exactly this --->[Black] (without brackets)": GOSUB StartTest
RANDOMIZE TIMER: ' To ensure this doesn't hurt anything
wPass# = GetInitialPassword("Black")
IF wPass# <> -1 THEN STOP:  ' Bug detected - Must return -1
OPEN GameName + ".pwd" FOR APPEND AS #1: CLOSE
OPEN GameName + ".pwd" FOR INPUT AS #1
IF EOF(1) THEN L$ = SPACE$(30) ELSE LINE INPUT #1, L$
CLOSE
IF LEN(L$) <> 30 THEN L$ = SPACE$(30)
IF LEFT$(L$, 15) <> pwW THEN LSET pwW = ""
IF RIGHT$(L$, 15) <> pwB THEN LSET pwB = ""
IF pwB = SPACE$(15) THEN STOP: ' Bug - Should have something
GOSUB Passed

Test$ = "Final test!": GOSUB StartTest
PRINT "Now we are just in a loop to show the encrypted"
PRINT "password value for possible study of technique"
DO
  t# = GetInitialPassword("Black")
  IF t# = 0 THEN EXIT DO
  PRINT t#
  pwdString = LTRIM$(STR$(t#))
  t# = VAL(pwdString)
  PRINT "Now re-enter the same password"
  IF NOT Authorized("Black", t#) THEN
    PRINT STRING$(30, "-"); ">You goofed or there's a bug"
  ELSE
    PRINT STRING$(30, "-"); ">OK"
  END IF
LOOP
SYSTEM

StartTest:
PRINT : PRINT : LINE INPUT "Press Enter to do next test: "; e$
CLS : PRINT "TEST: "; Test$: PRINT : PRINT
RETURN


Passed:
PRINT "------------ Passed Test -------------": PRINT : PRINT
RETURN

FUNCTION Authorized% (c$, pw#)
PRINT "Enter password for " + c$;
LINE INPUT ": "; pw$
IF pw$ = "" THEN EXIT FUNCTION
t# = Hash(pw$)
t$ = STR$(t#)
t# = VAL(t$)
IF t# = pw# THEN
  Authorized% = -1
ELSE
  Authorized% = 0
END IF
END FUNCTION

FUNCTION GetInitialPassword# (c$)
PRINT : PRINT
PRINT "Choose and enter the password for " + c$
PRINT "(Just press Enter if you are not that player)"
LINE INPUT "Password: "; p$
IF p$ = "" THEN GetInitialPassword# = 0: EXIT FUNCTION
IF p$ <> c$ THEN GetInitialPassword# = Hash(p$): EXIT FUNCTION

'-------------- Compute password for no-password path
RANDOMIZE TIMER
DO
  y# = RND * 44778439
  y$ = LTRIM$(STR$(y#))
LOOP WHILE LEN(y$) < 16 OR INSTR(y$, "D") > 0
y% = INSTR(y$, ".")
IF y% > 0 THEN MID$(y$, y%, 1) = MID$(y$, 16, 1)
IF c$ = "White" THEN LSET pwW = y$ ELSE LSET pwB = y$
'-------------- Read current password file (if any)
OPEN GameName + ".pwd" FOR APPEND AS #1: CLOSE
OPEN GameName + ".pwd" FOR INPUT AS #1
IF EOF(1) THEN L$ = SPACE$(30) ELSE LINE INPUT #1, L$
CLOSE
IF LEN(L$) <> 30 THEN L$ = SPACE$(30)
'-------------- Add the password for White
IF c$ = "White" THEN
  L$ = pwW + RIGHT$(L$, 15)
ELSE
  L$ = LEFT$(L$, 15) + pwB
END IF
'-------------- Save it
OPEN GameName + ".pwd" FOR OUTPUT AS #1
PRINT #1, L$: CLOSE
'-------------- Report no password required
GetInitialPassword# = -1
END FUNCTION

FUNCTION Hash# (pw$)
IF pw$ = "" THEN STOP: ' Bug in calling program
CONST c1 = 10000000#: CONST c2 = 84901
e# = RND(-57737): ' Good a place as any to start
DIM L AS INTEGER: L = LEN(pw$)
DIM pc(100) AS INTEGER: ' To speed up loop below
DIM i AS INTEGER, j  AS INTEGER
FOR i = 1 TO L: pc(i) = ASC(MID$(pw$, i, 1)): NEXT i
' OK, now compute hash
FOR i = 1 TO 3
  w# = 0
  DO WHILE w# < c1
    FOR j = 1 TO L
      w# = w# + SQR(c2 * RND * pc(j))
    NEXT j
  LOOP
  w# = RND(c1 - w#)
NEXT i
Hash# = RND * c1
END FUNCTION




    
This message has been edited by iorr5t from IP address 68.98.164.60 on Apr 14, 2006 12:21 PM
This message has been edited by iorr5t from IP address 68.98.164.60 on Apr 14, 2006 12:21 PM

Posted on Apr 10, 2006, 1:37 PM
from IP address 68.98.164.60

Respond to this message   

Return to Index


Response TitleAuthor and Date
Certification on Apr 10