'===========================================================================
' Subject: ANALYSING THE BIBLE                Date: 07-02-98 (22:29)       
'  Author: Bert van Dam                       Code: QB, QBasic, PDS        
'  Origin: bd1rsd@usa.net                   Packet: MISC.ABC
'===========================================================================
'BIBLE.BAS                                          November 1997

'This program is based on the technique used by Michael Drosnin, who
'used it to search the bible for names of people, and predict the future
'with it. Unfortinately using this technique on, say, Moby Dick renders
'equally interesting results.

'The technique is rather straing forward. Take a name to search for.
'Search for the first letter of that name in any (large) tekst. Then
'search for the next letter of the name. The distance between those to
'letters is now used to 'step' through the remaining tekst and search the
'rest of the letters of the name. If succesful the full tekst at the
'of the letters found will tell something about the future.

'Apparently the secret future predicting code has been hidden in the bible
'for 3000 years, according to Drosnin's claim. Ofcourse he conveniently
'forgets that the tekst of the bible has been re-written repeatedly. And
'changing just 1 letter also changes the predictions....

'Anyway, take a bible tekst (or anything else) and make your own
'predictions using this program. Written by Bert van Dam and donated to
'the public domain. I can be reached at Fido 2:285/750.14, or in the
'quick basic conference, or the internet BD1RSD@USA.NET


DIM letter AS STRING * 1


'this is the string to search for
Search$ = "Bert"

'this is the file to search in
OPEN "c:\qb45\techdox\qbt401.dox" FOR BINARY AS #1

CLS
Search$ = UCASE$(Search$)
COLOR 2, 0
PRINT "              ---===[ String Searcher ]===---"
COLOR 7, 0
Teller = 0
DO UNTIL EOF(1)
    'find first character in the search string
    failed = 0
    character$ = LEFT$(UCASE$(Search$), 1)
    DO
        Teller = Teller + 1
        GET #1, Teller, letter
        IF character$ = UCASE$(letter) THEN
            Startpoint = Teller                  'remember where the first
            EXIT DO                              'letter is found
        END IF
    LOOP UNTIL EOF(1)

    'search for the next character to determine the step size
    character$ = MID$(UCASE$(Search$), 2, 1)
    DO UNTIL EOF(1)
        Teller = Teller + 1
        GET #1, Teller, letter
        IF character$ = UCASE$(letter) THEN      'determine distance between
            StepSize = Teller - Startpoint       'first two letters, this is
            EXIT DO                              'the stepsize
        END IF
    LOOP

    'step forward en check for next letter
    nextpoint = Teller
    FOR Counter = 3 TO LEN(Search$)
        character$ = MID$(UCASE$(Search$), Counter, 1)
        nextpoint = nextpoint + StepSize
        GET #1, nextpoint, letter                'see if the other letters
        IF EOF(1) THEN                           'can be found, the same
            'no more letters in the file         'distance apart. if the
            failed = 1                           'next letter isn't found
            EXIT FOR                             'or if the file ends this
        END IF                                   'search has failed
        IF character$ <> UCASE$(letter) THEN
            'character doesn't match
            failed = 1
            EXIT FOR
        END IF
    NEXT Counter

    'all letters of the search string could be found at equal
    'distances, print some data on the screen
    IF failed <> 1 THEN
        OnceFound = 1
        PRINT
        PRINT "Ocurrence of search string "; Search$; " succesfully found, starting at"
        PRINT "file location"; Startpoint; "with letters spaced"; StepSize; "character(s) apart."
    END IF

    'reset teller to continue search
    Teller = Startpoint

LOOP

'if any of the search attempts was succesful give the oppertunity to see
'the part of the file where is was found
IF OnceFound = 1 THEN
    DO
        PRINT
        PRINT "Which section of the file would you like to see (0 = quit);"
        INPUT SeeLoc
        IF SeeLoc = 0 THEN EXIT DO
        PRINT "What was the stepsize ";           'required to color the
        INPUT StepSize                            'letters found
        PRINT
        PRINT
        COLOR 2, 0
        NumberOfColorings = 0
        Coloring = SeeLoc
        IF SeeLoc < LOF(1) THEN
            FOR Teller = SeeLoc TO SeeLoc + 240
                IF Teller < LOF(1) THEN
                    GET #1, Teller, letter
                    IF Teller = Coloring THEN
                        COLOR 14, 0
                        letter = UCASE$(letter)
                        NumberOfColorings = NumberOfColorings + 1
                        IF NumberOfColorings = LEN(Search$) THEN
                            Coloring = 0
                        ELSE
                            Coloring = Coloring + StepSize
                        END IF
                    ELSE
                        COLOR 2, 0
                    END IF
                    PRINT letter;
                END IF
            NEXT Teller
            COLOR 7, 0
        ELSE
            PRINT
            PRINT "Number to high, the file ends at"; LOF(1)
            PRINT
        END IF
        PRINT
    LOOP
ELSE
    PRINT
    PRINT "Search string "; Search$; " not found."
END IF
COLOR 7, 0
PRINT
PRINT "Program terminated normally"
CLOSE #1
END
