home *** CD-ROM | disk | FTP | other *** search
- 'DECRYPT.BAS
- 'Version 1.0 July 4, 1993
- 'Copyrighted 1993, by Gabriel Fineman
- 'Donated as FREEWARE
- 'See details under Help
- 'Written in Turbo Basic
- 'From KFIX (a Mass-11 utility by the
- ' same Author)
-
- DEFINT A,Z 'Default all variables to integer
-
- CLS 'Clear screen
-
- 'Get and test command line
-
- T$ = COMMAND$
- IF T$ = "" THEN
- GOSUB GetInput 'Interactive with User
- ELSE
- GOSUB COMMANDLINE 'Non-Interactive
- END IF
- GOSUB INITIALIZE
-
- Test:
- FOR I = 2 TO 23 'Max key length
- LOCATE 7 'On line seven
- PRINT "TESTING KEY LENGTH " I 'Keep user informed
- C = 0 'count of letters found
- R$ = "" 'accumulate letters found
- FOR J = 1 TO I 'for each char in this key length
- J1 = J
- TestA: 'Convert a first time
- JA = I+J1 'constant
- IF J1 > 30 THEN GOTO TestB 'too large to test
-
- IF FNSKIP(J1) THEN 'if variable information
- J1 = J1+I 'try next multiple
- GOTO TestA
- END IF
- T1 = ( K(J1) XOR (JA) ) XOR E(J1) 'algorthym
-
- J2 = J1+I
- JB = J2+I
- TestB: 'Convert a second time
- IF J2 > 30 THEN GOTO TestC
- IF FNSKIP(J2) THEN
- J2 = J2+I
- JB = JB+I
- GOTO TestB
- END IF
-
- T2 = ( K(J2) XOR (JB) ) XOR E(J2)
- GOTO Printing
-
- TestC: 'Unable to convert 2nd time
- IF (LEN(R$)>0) AND (MID$(R$,LEN(R$),1) <> "?") THEN T2=T1
-
- Printing:
- IF T1=T2 THEN 'if conversions the same
- R$ = R$ + CHR$(T1) 'must be correct
- C = C+1
- END IF
-
- IF T1<>T2 THEN R$ = R$ + "?" '? if different conversions
-
- NEXT
-
- IF C*2 > I THEN 'if more than 1/2 found
- LOCATE Row
- Row = Row+1
- IF I<10 THEN 'show password
- PRINT "Key length " I " has a password of " R$
- D = D+1
- ELSE
- PRINT "Key length " I " has a password of " R$
- D = D+1
- END IF
- END IF
-
- NEXT 'End of main loop
-
- LOCATE 7
- PRINT " "
- LOCATE ROW
- IF D = 0 THEN PRINT "NO LIKELY KEYS FOUND"
- LOCATE ROW+2
- INPUT "Press any key to exit", Z$
- GOTO ENDING0
-
- ERROR1:
- LOCATE 9
- PRINT "NOSUCH FILE AS " S$
- INPUT "Press any key to exit", Z$
- RESUME ENDING0
-
- '_______________________________________________
-
- 'GOSUB SUBROUTINES
- '_______________________________________________
-
-
-
- COMMANDLINE: 'GOSUB subroutine to parse and set from command line
- T$ = UCASE$(T$)
- INTERACTIVE = 0
- WHILE LEFT$(T$,1) = " " ' Flush left
- T$ = MID$(T$,2)
- WEND
- I = INSTR (T$," ") 'Strip file name
- J = INSTR (T$,"/")
- IF I=J THEN
- K=999
- ELSE
- IF I>J THEN
- IF J>0 THEN K=J ELSE K=I
- ELSE
- IF I>0 THEN K=I ELSE K=J
- END IF
- END IF
- S$ = LEFT$(T$,K) 'File name into S
- PRINT "Finding password for file " S$
- T$ = MID$(T$,K) 'Options into T
-
- RETURN
-
- '-----------------------------------------------
-
-
- GETINPUT: 'GOSUB subroutine to get interactive input
- CLS
- PRINT TAB(30); "DECRYPT PASSWORD"
- PRINT
- GetInput1:
- PRINT "Enter ? for help"
- PRINT
- INPUT "Enter name of encrypted file: ",S$
- IF S$ = "" THEN GOTO ENDING0
- IF S$ = "?" THEN
- GOSUB HelpIndex
- GOTO GetInput
- END IF
- S$ = UCASE$(S$)
- RETURN
-
- '-----------------------------------------------
-
-
- HELPINDEX: 'GOSUB subprogram to give online help
- Help1:
- SK=1 'Get index screen #1
- GOSUB GetScreen
-
- INPUT "Return to continue",OK$
- RETURN
-
- '-----------------------------------------------
-
- INITIALIZE:
- 'print "fnexists(" S$ ") = " FNEXISTS(S$)
- 'IF NOT FNEXISTS(S$) THEN GOTO ERROR1 'See if good name
- ON ERROR GOTO ERROR1
- OPEN S$ FOR BINARY AS #1 'Open file to decrypt
- ON ERROR GOTO ERROR0
-
- GET$ #1, 50, A$ 'Get first 50 bytes
-
- CK$ = MID$(A$,1,4) '[FF]WPC
- IF CK$ = "" OR_
- (ASC(MID$(CK$,1,1))=&HFF AND_
- ASC(MID$(CK$,2,1))=&H57 AND_
- ASC(MID$(CK$,3,1))=&H50 AND_
- ASC(MID$(CK$,4,1))=&H43) THEN
- ELSE
- PRINT S$ " is not a WordPerfect file, let alone encrypted."
- INPUT "Press any key to exit", Z$
- GOTO ENDING0
- END IF
-
- CK$ = MID$(A$,13,4) 'Key checksum
- IF CK$ = "" OR_
- (ASC(MID$(CK$,1,1))=&H00 AND_
- ASC(MID$(CK$,2,1))=&H00 AND_
- ASC(MID$(CK$,3,1))=&H00 AND_
- ASC(MID$(CK$,4,1))=&H00) THEN
- PRINT S$ " is not an encrypted WordPerfect file."
- INPUT "Press any key to exit", Z$
- GOTO ENDING0
- END IF
-
- DIM N(1:8) 'Numbers to skip
- N(1) = 7
- N(2) = 8
- N(3) = 11
- N(4) = 12
- N(5) = 13
- N(6) = 21
- N(7) = 23
- N(8) = 27
-
- DIM E(1:48) 'Encrypted constants
- FOR I = 17 TO 46
- E(I-16) = asc(MID$(A$,I,1))
- NEXT
-
-
- DIM K(1:48) 'Known constants
- K(1) = &HFB
- K(2) = &HFF
- K(3) = &H05
- K(4) = &H00
- K(5) = &H32
- K(6) = &H00
- K(7) = &H00 'Skip
- K(8) = &H00 'Skip
- K(9) = &H00
- K(10) = &H00
- K(11) = &H07 'Skip
- K(12) = &H00 'Skip
- K(13) = &H00 'Skip
- K(14) = &H00
- K(15) = &H00
- K(16) = &H00
- K(17) = &H42
- K(18) = &H00
- K(19) = &H00
- K(20) = &H00
- K(21) = &H02 'Skip
- K(22) = &H00
- K(23) = &H56 'Skip
- K(24) = &H00
- K(25) = &H00
- K(26) = &H00
- K(27) = &H00 'Skip
- K(28) = &H00
- K(29) = &H00
- K(30) = &H00
- row = 9
- D = 0
- GOSUB InitializeScrArray
-
- RETURN
-
- '-----------------------------------------------
-
- GetScreen: 'GOSUB to display screen from file
- CLS
- GOSUB InitializeScrArray
- PRINT SCR$(SK)
- RETURN
-
- '-----------------------------------------------
-
-
- InitializeScrArray: 'GOSUB routine to initialize help matrix
- DIM STATIC SCR$(2) 'Fast and short but hard to space
- LFCR$ = CHR$(10)+CHR$(13)
- SN$ = LFCR$+SPACE$(10)
- SS$ = CHR$(10)
- SI$ = SS$+SPACE$(15)
-
- SCR$(1) = SPACE$(20)+"WordPerfect Decryption Passwords"+SN$_
- +"When you forget your password this program can help "_
- +"recover it." + SS$ _
- + "It tests possible key lengths of 1-23. If it can "
- SCR$(1) = SCR$(1) + "decypher at least half of the characters, "_
- +"it shows you the possible key. If the same letter is "_
- +"shown twice ina row, it may not be correct the second "_
- +"time."
- SCR$(1) = SCR$(1) + " Hopefully, you will get enough toguess the "_
- +"password."+SN$
- SCR$(1) = SCR$(1) + "The program will accept a file name on the "_
- +"command line. If none is provided, it asks you for the "_
- + "file name." + SN$_
- +"This program is based on a 1990 article by Ms. Helen Bergen "_
- +"at the" + SS$ + "Queensland University, reachable at "
- SCR$(1) = SCR$(1) + "<CSZBERGEN@qut.edu.au> on the Internet." + SN$
- SCR$(1) = SCR$(1) + "The program was written by Gabriel Fineman in "_
- +"July of 1993 and is designated by the author as "_
- +"FREEWARE that may be used and modified by anyone forany "_
- +"purpose. The author may be reached on GENIE as "_
- +"<GFINEMAN@genie.geis.com>." + LFCR$
- RETURN
-
- '_______________________________________________
-
- 'FUNCTIONS
- '_______________________________________________
-
- DEF FNSKIP (i) 'Test if to skip this i
- LOCAL J
- FNSKIP = 1
- FOR J = 1 TO 8
- IF N(J)=I THEN GOTO SKIPEND
- NEXT
- FNSKIP = 0
- SkipEnd:
- END DEF
-
-
- DEF FNEXISTS (N$) 'Test if N$ exists
- FNEXISTS = 0
- ON ERROR GOTO ExistsR
- OPEN N$ FOR INPUT AS #9
- CLOSE #9
- FNEXISTS=1
- GOTO Exists
-
- ExistsR:
- ON ERROR GOTO 965
- RESUME Exists
-
- Exists:
- END DEF
-
- '________________________________________________
-
- 'Error Trapping Routines
- '________________________________________________
-
- 964:
- 965:
- Error0:
- Print "Error trap ERR at line ERL"
- RESUME ENDING0
-
- '_______________________________________________
-
- 'EXIT FROM PROGRAM
- '_______________________________________________
-
- ENDING0:
- RESET
- END