ProgramList Mac

Joined: January 1st, 1970, 12:00 am

January 23rd, 2002, 2:44 am #1

The first program I ever wrote was for the NORC
http://www.columbia.edu/acis/history/norc-herald.html

I had no access to the 2 million dollar computer, so I don't know if my programs had bugs or not. I learned from a book and was excited about computer power.

At the University of Texas in 1958, I wrote some programs as part of a numerical analysis mathematics course on the IBM 650.
http://www.columbia.edu/acis/history/650.html

The machine had no firmware, so one had to manually enter the first instructions through the console. These instructions were the bootstrap that then loaded the software, which was a card deck.

At the time, the general consensus was that, with the invention of a language scientists and numerical analysts could use, FORTRAN, there was no further need for programmers!

I then joined IBM in 1958 as a programmer and was trained on the SAC/SAGE computer
http://www.mitre.org/about/sage.html
to write "maintenance programs". It seems that the zillions of electronic tubes used could fail, so as I had a background in Electrical Engineering, I was to write programs to vary the plate voltage (we had an instruction for that!) of a given index register or other live register and see if it was "about to fail". If so, I swapped to the alternate tube and popped the failing tube out and lit a light on the computer so the engineers could remove it and supply a new one.

Well, I later got into assembly programming and, as they say, "the rest is history".

One item: the first "Program I am proud of" was a little one-card program for the IBM-709 called "Busy Bee". You see, we programmers had to come in during the middle of the night at IBM and debug on test computers almost ready for shipment to a customer. But sometimes we had to leave the computer for a snack or to rest or redesign our programs and while we were away, the engineers would see the computer was idle and do power off. That was a big deal in those days. It took a LONG time to power up again. So my program would blink the lights at random and it appeared to be working on some complex problem. All the programmers had a Busy Bee card in their possession when in the lab.

My first personal computer was the Commodore VIC-20
http://www.old-computers.com/museum/computer.asp?c=252

It was connected to your TV and had a display of about 10 lines, 40 characters wide. It was mainly for games, and I wrote many programs, such as
An Algebra Drill: Solve 2 equations in 2 unknowns
BINGO
which I later converted to BASICA. These are published (see replies)

I actually wrote a program to connect to the IBM mainframe we were using at the office and demonstrated to management that microcomputers would be an excellent interface to the mainframe. This was ignored and the company eventually was forced out of the business when microcomputers became popular.

I used the VIC-20 for 5 years and still have it in storage with many cassette tapes. But finally I gave in a bought the next home computer: the DOS-based IBM 286
http://www.old-computers.com/museum/com ... st=1&c=260

This I used for many years. It was perfect and did everything I wanted. But it had no mouse and when the Internet became usable, I finally got my current system: DELL 500 Mhz with WindowsNT.

As you can guess, I have programmed in machine language, COBOL, FORTRAN, PL/I and you name it. But I am still fascinated with DOS/QBasic.

Mac
Last edited by iorr5t on May 18th, 2007, 8:52 pm, edited 1 time in total.
Quote
Like
Share

Joined: January 1st, 1970, 12:00 am

January 26th, 2002, 10:58 pm #2

DECLARE SUB CSub.Pause (Msg AS STRING)
DECLARE SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
DECLARE SUB CSub.GenKey (strKeyE AS STRING)
DECLARE SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
DECLARE SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
DECLARE SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Zap (strF1 AS STRING)
DIM strKeyI AS STRING: 'Internal Key
DIM strKeyE AS STRING: 'External Key
DIM fleTest AS STRING
DIM fleOK AS INTEGER
GOTO Main

REM SuperC.bas - - - - - Super-Crypto with Crypto-Nite
REM * ** *** An Encryption/Decryption Machine *** ** *
REM Permission granted for personal use of this to keep diaries, etc.
REM Components may not be copied to other programs.
REM Instructions:
REM File to be Encrypted: Plain.txt
REM File to be Decrypted: Crypto.txt
REM When prompted, enter a key you make up.
REM Sample Key: J3mm29
REM Sample Key: My dog has fleez and has to sneeze
REM Sample Key: On November 11 I downloaded this great machine

TestFile:
ON ERROR GOTO L331
OPEN fleTest FOR INPUT AS #1
ON ERROR GOTO 0
fleOK = 1
CLOSE
RETURN
L331:
RESUME L332
L332:
ON ERROR GOTO 0
fleOK = 0
RETURN

Main:
' Step 1: Find out if there is something to do
fleTest = "Plain.txt": GOSUB TestFile
Plain% = fleOK
fleTest = "Crypto.txt": GOSUB TestFile
Crypto% = fleOK
SELECT CASE (2 * Plain%) + Crypto%
CASE 0:
  CSub.Pause "There is nothing to do. Create Plain.txt or Crypto.txt"
  SYSTEM
CASE 3:
  CSub.Pause "You need to get rid of Plain.txt or Crypto.txt": SYSTEM
END SELECT

' Step 2: Get the Internal Key
fleTest = "SuperC.dat": GOSUB TestFile
IF fleOK = 0 THEN
   OPEN fleTest FOR OUTPUT AS #1
   PRINT #1, "Key Verification File"
   CLOSE
END IF
CSub.GetKeyI strKeyI, fleTest
IF strKeyI = "" THEN CSub.Pause "Terminating Run": SYSTEM

' Step 3: Encrypt or Decrypt the Message
IF Plain% = 1 THEN GOTO Encrypt ELSE GOTO Decrypt

REM                      E N C R Y P T I O N
Encrypt:
PRINT "Encrypting . . ."
CSub.GenKey strKeyE
DIM lngKernal AS LONG
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Convert "Normal to Markup", lngKernal, "Plain.txt", "Markup.txt"
CSub.Markup "Encrypt", lngKernal, "Markup.txt"
CSub.IO "Write", strKeyE, "Markup.txt", "Crypto.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Plain.txt"
SYSTEM

REM                      D E C R Y P T I O N
Decrypt:
PRINT "Decrypting . . ."
CSub.IO "Read", strKeyE, "Crypto.txt", "Markup.txt"
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Markup "Decrypt", lngKernal, "Markup.txt"
CSub.Convert "Markup to Normal", lngKernal, "Markup.txt", "Plain.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Crypto.txt"
SYSTEM

SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM c$(255): ' Translate to Char
DIM c0$(255): 'Translate to Bin (no prefix)
DIM c1$(255): 'Translate to Bin (prefix 125)
DIM c2$(255): 'Translate to Bin (prefix 126)
DIM V13 AS STRING * 1: V13 = CHR$(13)
DIM V10 AS STRING * 1: V10 = CHR$(10)
DIM V32 AS STRING * 1: V32 = " "
DIM ndxM AS LONG: ' Markup Index
DIM ndxN AS LONG: ' Normal Index
DIM chrM AS STRING * 1: ' Markup Character
DIM chrN AS STRING * 1: ' Normal Character

SELECT CASE strCMD
CASE "Normal to Markup"
  GOSUB Init.Tables
  Normal$ = strF1
  Markup$ = strF2
  GOSUB Normal.to.Markup
CASE "Markup to Normal"
  GOSUB Init.Tables
  Markup$ = strF1
  Normal$ = strF2
  GOSUB Markup.to.Normal
CASE ELSE: STOP
END SELECT
EXIT SUB

Markup.to.Normal:
OPEN Markup$ FOR BINARY AS #1
OPEN Normal$ FOR OUTPUT AS #2: CLOSE #2: ' Ensure zero size
OPEN Normal$ FOR BINARY AS #2
ndxN = 1
lngS = LOF(1)
GOSUB Compute.lngO
z% = 1
FOR ndxM = lngO TO LOF(1): GOSUB DoMarkup: NEXT ndxM
FOR ndxM = z% TO lngO - 1: GOSUB DoMarkup: NEXT ndxM
CLOSE
RETURN

DoMarkup:
GET #1, ndxM, chrM
SELECT CASE chrM
CASE CHR$(123):
  PUT #2, ndxN, V13: ndxN = ndxN + 1
  PUT #2, ndxN, V10: ndxN = ndxN + 1
CASE CHR$(124):
  PUT #2, ndxN, V32: ndxN = ndxN + 1
CASE CHR$(125):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c1$(ASC(chrM)): ndxN = ndxN + 1
CASE CHR$(126):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c2$(ASC(chrM)): ndxN = ndxN + 1
CASE ELSE:
  PUT #2, ndxN, chrM: ndxN = ndxN + 1
END SELECT
RETURN

Normal.to.Markup:
OPEN Markup$ FOR OUTPUT AS #2: CLOSE #2:  'Ensure size zero
OPEN Normal$ FOR BINARY AS #1
lngS = 0: lngO = 0
GOSUB DoPass: 'Compute lngS
OPEN Markup$ FOR BINARY AS #2
GOSUB Compute.lngO
ndxM = lngO - 1
GOSUB DoPass: 'BuildFile
CLOSE
RETURN

Compute.lngO:
w# = RND(-13 - lngKernal)
w# = 0: FOR i = 1 TO 10: w# = w# + (RND(1) * 173): NEXT i
w# = RND(-13 - w# * 55773)
lngO = INT((RND(1) * lngS)) + 1
IF lngO > lngS THEN lngO = 1
IF zzzO > 0 THEN lngO = zzzO
RETURN

DoPass:
DIM strL AS STRING: ' Just a work string
FOR ndxN = 1 TO LOF(1)
  GET #1, ndxN, chrN
  IF ASC(chrN) = 13 THEN
    DIM chrNt AS STRING * 1
    GET #1, ndxN + 1, chrNt
    IF ASC(chrNt) = 10 THEN
      strL = strL + CHR$(123)
      ndxN = ndxN + 1
    ELSE
      strL = strL + c$(ASC(chrN))
    END IF
  ELSE
    strL = strL + c$(ASC(chrN))
  END IF
  IF LEN(strL) > 79 THEN GOSUB WritestrL
NEXT ndxN
IF LEN(strL) > 0 THEN GOSUB WritestrL
RETURN

WritestrL:
IF lngO = 0 THEN lngS = lngS + LEN(strL): strL = "": RETURN
FOR ll = 1 TO LEN(strL)
  LSET chrM = MID$(strL, ll, 1)
  ndxM = ndxM + 1: IF ndxM > lngS THEN ndxM = 1
  PUT #2, ndxM, chrM
NEXT ll
strL = ""
RETURN

Init.Tables:
FOR i = 33 TO 122
  c$(i) = CHR$(i)
  c0$(i) = CHR$(i)
NEXT i
'
k = 32
FOR i = 0 TO 31
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
FOR i = 123 TO 180
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
'
k = 32
FOR i = 181 TO 255
  k = k + 1
  c$(i) = CHR$(126) + CHR$(k)
  c2$(k) = CHR$(i)
NEXT i
'
c$(32) = CHR$(124)
RETURN
'
END SUB

SUB CSub.GenKey (strK AS STRING)
DIM intM AS INTEGER
RANDOMIZE TIMER
w$ = DATE$ + TIME$
FOR i = 1 TO LEN(w$)
  c% = INT(94 * RND(1))
  intM = ASC(MID$(w$, i, 1))
  intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  MID$(w$, i, 1) = CHR$(intM)
NEXT i
strK = w$
END SUB

SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
CLS
LOCATE 3, 35: PRINT "Crypto-Nite Version 1.3"
LOCATE 7, 1
PRINT "Enter your Key, or hit Enter to terminate run.": PRINT
INPUT "Key: ", strKeyI
IF strKeyI = "" THEN EXIT SUB
DIM strV AS STRING: ' A 3-digit verifier to detect typo errors
GOSUB GetV
OPEN fleKeyV FOR INPUT AS #1: LINE INPUT #1, l$
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  IF LEFT$(l$, 3) = strV THEN strV = ""
LOOP
CLOSE
IF strV = "" THEN EXIT SUB
PRINT "I haven't seen this key before. What do you want me to do?"
PRINT "  1 - Accept this as a new key"
PRINT "  2 - Terminate run and start over"
DO: k$ = INKEY$: LOOP WHILE ((k$ <> "1") AND (k$ <> "2"))
IF k$ = "2" THEN strKeyI = " ": EXIT SUB
OPEN fleKeyV FOR APPEND AS #1
PRINT #1, strV; " created on "; DATE$; " at "; TIME$
CLOSE
EXIT SUB

GetV:
w$ = strKeyI + CHR$(13)
DIM y AS INTEGER
y = RND(-577823)
DIM e1 AS DOUBLE, e2 AS DOUBLE, e3 AS DOUBLE
DIM i, j
DO
FOR i = 1 TO 100
j = j + 1: IF j > LEN(w$) THEN j = 1
e1 = e1 + (RND(1) * ASC(MID$(w$, j, 1)))
e2 = e2 + (RND(1) * ASC(MID$(w$, j, 1)))
NEXT i
e1 = 1 + e1 - INT(e1)
e2 = 1 + e2 - INT(e2)
e3 = e1 * e2
WHILE e3 > 1: e3 = e3 - RND(1): WEND
w$ = STR$(e3)
LOOP WHILE LEN(w$) < 17
strV = MID$(w$, 10, 3)
RETURN
END SUB

SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DIM fleB AS STRING: 'Binary File
DIM ndxB AS LONG: ' Index for Binary file
DIM chrB AS STRING * 1: ' Character of Binary file
DIM fleQ AS STRING: 'Sequential file
DIM strQ AS STRING: ' Line in sequential file

SELECT CASE strCMD
CASE "Write": GOSUB IOWrite
CASE "Read": GOSUB IORead
END SELECT
CLOSE
EXIT SUB

IOWrite:
fleQ = strF2
fleB = strF1
OPEN fleQ FOR OUTPUT AS #1
PRINT #1, strKeyE
strQ = ""
OPEN fleB FOR BINARY AS #2
FOR ndxB = 1 TO LOF(2)
GET #2, ndxB, chrB
IF chrB = "&" THEN strQ = strQ + CHR$(127) ELSE strQ = strQ + chrB
' Output strings are 80-characters, suitable for transmission
IF LEN(strQ) > 79 THEN PRINT #1, strQ: strQ = ""
NEXT ndxB
IF LEN(strQ) > 0 THEN PRINT #1, strQ
RETURN

IORead:
fleQ = strF1
fleB = strF2
OPEN fleQ FOR INPUT AS #1
LINE INPUT #1, strKeyE
OPEN fleB FOR BINARY AS #2
ndxB = 0
DO WHILE NOT EOF(1)
LINE INPUT #1, strQ
FOR i = 1 TO LEN(strQ)
LSET chrB = MID$(strQ, i, 1)
IF chrB = CHR$(127) THEN LSET chrB = "&"
ndxB = ndxB + 1
PUT #2, ndxB, chrB
NEXT i
LOOP
RETURN

END SUB

SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM strW AS STRING
WHILE LEN(strW) < 100: strW = strW + strKey: WEND
DIM c%(100)
FOR i = 1 TO 100: c%(i) = ASC(MID$(strW, i, 1)): NEXT i
FOR secur.cnt = 1 TO intS: GOSUB Scramble: NEXT secur.cnt
EXIT SUB
Scramble:
y# = RND(-13 - lngKernal)
FOR SwapI = 1 TO 100: SWAP c%(1 + INT(RND(1) * 100)), c%(1 + INT(RND(1) * 100)): NEXT SwapI
DIM dblW AS DOUBLE
dblW = 0
FOR i = 1 TO 100: dblW = dblW + (c%(i) * RND(1)): NEXT i
lngKernal = (dblW - INT(dblW)) * 2147483647
RETURN
END SUB

SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
REM Copyright 2001 Hilliard McLamore
y# = RND(-13 - lngKernal)
OPEN strF1 FOR BINARY AS #1
DIM chrM AS STRING * 1
DIM ndxM AS LONG
DIM intM AS INTEGER
FOR ndxM = 1 TO LOF(1)
  GET #1, ndxM, chrM
  intM = ASC(chrM)
  c% = INT(94 * RND(1))
  SELECT CASE strCMD
  CASE "Encrypt": intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  CASE "Decrypt": intM = intM - c%: IF intM < 33 THEN intM = intM + 94
  END SELECT
  LSET chrM = CHR$(intM)
  PUT #1, ndxM, chrM
NEXT ndxM
CLOSE
END SUB

SUB CSub.Pause (Msg AS STRING)
PRINT : PRINT Msg: PRINT
PRINT "---Press any key to continue"
SLEEP
END SUB

SUB CSub.Zap (strF1 AS STRING)
OPEN strF1 FOR BINARY AS #1
DIM ndx1 AS LONG
DIM chr1 AS STRING
chr1 = "Q"
FOR ndx1 = 1 TO LOF(1): PUT #1, ndx1, chr1: NEXT ndx1
CLOSE
KILL strF1
END SUB
Last edited by iorr5t on May 5th, 2006, 12:57 pm, edited 1 time in total.
Quote
Like
Share

Joined: January 1st, 1970, 12:00 am

January 27th, 2002, 12:30 am #3

In the directory you call SuperC from, you will have one of the following files:
„h Plain.txt
„h Crypto.txt

If you have Plain.txt, the program will erase it in such a manner as to make it completely unrecoverable. This is so any Enemy who gets access to your computer cannot find it. The program will produce Crypto.txt which is suitable to be transmitted to anyone who has a copy of Crypto.bas and who knows your Key.

If you have Crypto.txt, the reverse is done. It is your responsibility to take care of Plain.txt. Crypto.txt is erased so that there is no copy of both available to whoever might want to figure out your Key.

If you examine Crypto.bas, you will find a two lines that start: "CSub.Kernal 7". The seven is a security level. The higher you make it, the harder for someone to discover your key by trail and error. Seven is quite high and is fast. I tried 500 and the delay was about 15 seconds before starting encryption or decryption. The security of an individual message is not affected ¡V It is already hopelessly difficult to decrypt. This just keeps someone from trying all possible keys. The level of 7 would mean a reasonable powerful home PC would take a few weeks to break your key. The level 500 means a few trillion years. A supercomputer might do it in a few weeks.

To further make life miserable for a cryptographer, the text is folded before encryption. This is so the cryptographer doesn't know that the last character is a chr$(13) or whatever normally ends txt files.

If you encrypt a message using a given Key, and then encrypt the same message again, you will notice the cryptograms are not similar. This is part of the security. However, either one will decrypt successfully.

A short key, such as "MyKey" could be guessed at security level 7 in a few hours (by a trained cryptographer who wrote a C++ program to emulate the decryption process.) So use something longer such as "Fat dogs eat too much". This will take weeks even at level 7.

The security afforded by this program is far more than needed by any normal person, but was provided as an intellectual exercise. I omitted one piece of code that would make encryption impossible without the key. This is to give the CIA a chance in case bad people get hold of the logic. But don't worry, I guarantee nobody will decrypt the messages you may want to send to your friends using this program.

By the way, there is another feature. A file, SuperC.dat, is kept with entries such as
Key Verification File
935 created on 11-04-2001 at 19:45:43

This is just to protect you from errors. The file is not required and can be safely deleted. The entries correspond to keys you have chosen. You can delete entries also.

Let's say you have a friend who has a copy of Crypto.bas and you have agreed on the password "My house is near the park." Now you want to send a message and you enter the password, but forget to capitalize the "M". The program will recognize this as a new password and warn you. Great! Otherwise, you would have sent a message your friend cannot decrypt.
Quote
Like
Share

codeworm
codeworm

January 28th, 2002, 3:48 am #4

The first program I ever wrote was for the NORC
http://www.columbia.edu/acis/history/norc-herald.html

I had no access to the 2 million dollar computer, so I don't know if my programs had bugs or not. I learned from a book and was excited about computer power.

At the University of Texas in 1958, I wrote some programs as part of a numerical analysis mathematics course on the IBM 650.
http://www.columbia.edu/acis/history/650.html

The machine had no firmware, so one had to manually enter the first instructions through the console. These instructions were the bootstrap that then loaded the software, which was a card deck.

At the time, the general consensus was that, with the invention of a language scientists and numerical analysts could use, FORTRAN, there was no further need for programmers!

I then joined IBM in 1958 as a programmer and was trained on the SAC/SAGE computer
http://www.mitre.org/about/sage.html
to write "maintenance programs". It seems that the zillions of electronic tubes used could fail, so as I had a background in Electrical Engineering, I was to write programs to vary the plate voltage (we had an instruction for that!) of a given index register or other live register and see if it was "about to fail". If so, I swapped to the alternate tube and popped the failing tube out and lit a light on the computer so the engineers could remove it and supply a new one.

Well, I later got into assembly programming and, as they say, "the rest is history".

One item: the first "Program I am proud of" was a little one-card program for the IBM-709 called "Busy Bee". You see, we programmers had to come in during the middle of the night at IBM and debug on test computers almost ready for shipment to a customer. But sometimes we had to leave the computer for a snack or to rest or redesign our programs and while we were away, the engineers would see the computer was idle and do power off. That was a big deal in those days. It took a LONG time to power up again. So my program would blink the lights at random and it appeared to be working on some complex problem. All the programmers had a Busy Bee card in their possession when in the lab.

My first personal computer was the Commodore VIC-20
http://www.old-computers.com/museum/computer.asp?c=252

It was connected to your TV and had a display of about 10 lines, 40 characters wide. It was mainly for games, and I wrote many programs, such as
An Algebra Drill: Solve 2 equations in 2 unknowns
BINGO
which I later converted to BASICA. These are published (see replies)

I actually wrote a program to connect to the IBM mainframe we were using at the office and demonstrated to management that microcomputers would be an excellent interface to the mainframe. This was ignored and the company eventually was forced out of the business when microcomputers became popular.

I used the VIC-20 for 5 years and still have it in storage with many cassette tapes. But finally I gave in a bought the next home computer: the DOS-based IBM 286
http://www.old-computers.com/museum/com ... st=1&c=260

This I used for many years. It was perfect and did everything I wanted. But it had no mouse and when the Internet became usable, I finally got my current system: DELL 500 Mhz with WindowsNT.

As you can guess, I have programmed in machine language, COBOL, FORTRAN, PL/I and you name it. But I am still fascinated with DOS/QBasic.

Mac
X{<Ux*(g85L0hU-Q=R
^c.8CXOsbK)x0Y0S,b!GvNrx5|9y~lKSGeo,!k$Q)EUdBkjj_De+#G2bz0>!\(S{PSR^s)O0X2ZOA\RL
ZwJ<hg%1eYy\G0l]kLZ)4?Imcerj\LW/=N.!/yV7TFcvaTvEt"^JN?vn6I[9yhw[E1n8YPana-ja({^H
GIK[.~eL3r%8_>Q5+[~j`K/~UIheDnZ-p&Y#e'v}sL-qU,`I0iA(dEVxYTP0<:lRaGp0e[~9pbIcTYZ|
1vI;`9`M5X:]HR}ye6MU~=6Fo#`0Y5-w&Py[00Duu+S;.UzzomcX*6x_1XNqv!:O]#''/=!-"}D*21;5
xW?Q?h}bZq*!N}G`Oi_3%c3Zn*Qaiqww}emceO)_uN1sCV*gVT9IN8pdE}'#Ku|Pd7a(0JL1?48)>.5C
9A2ee|6:nu:7shJnyRw?'2Pg^A~mh#4oz"\}
Quote
Share

Joined: January 1st, 1970, 12:00 am

February 10th, 2002, 11:53 pm #5

The first program I ever wrote was for the NORC
http://www.columbia.edu/acis/history/norc-herald.html

I had no access to the 2 million dollar computer, so I don't know if my programs had bugs or not. I learned from a book and was excited about computer power.

At the University of Texas in 1958, I wrote some programs as part of a numerical analysis mathematics course on the IBM 650.
http://www.columbia.edu/acis/history/650.html

The machine had no firmware, so one had to manually enter the first instructions through the console. These instructions were the bootstrap that then loaded the software, which was a card deck.

At the time, the general consensus was that, with the invention of a language scientists and numerical analysts could use, FORTRAN, there was no further need for programmers!

I then joined IBM in 1958 as a programmer and was trained on the SAC/SAGE computer
http://www.mitre.org/about/sage.html
to write "maintenance programs". It seems that the zillions of electronic tubes used could fail, so as I had a background in Electrical Engineering, I was to write programs to vary the plate voltage (we had an instruction for that!) of a given index register or other live register and see if it was "about to fail". If so, I swapped to the alternate tube and popped the failing tube out and lit a light on the computer so the engineers could remove it and supply a new one.

Well, I later got into assembly programming and, as they say, "the rest is history".

One item: the first "Program I am proud of" was a little one-card program for the IBM-709 called "Busy Bee". You see, we programmers had to come in during the middle of the night at IBM and debug on test computers almost ready for shipment to a customer. But sometimes we had to leave the computer for a snack or to rest or redesign our programs and while we were away, the engineers would see the computer was idle and do power off. That was a big deal in those days. It took a LONG time to power up again. So my program would blink the lights at random and it appeared to be working on some complex problem. All the programmers had a Busy Bee card in their possession when in the lab.

My first personal computer was the Commodore VIC-20
http://www.old-computers.com/museum/computer.asp?c=252

It was connected to your TV and had a display of about 10 lines, 40 characters wide. It was mainly for games, and I wrote many programs, such as
An Algebra Drill: Solve 2 equations in 2 unknowns
BINGO
which I later converted to BASICA. These are published (see replies)

I actually wrote a program to connect to the IBM mainframe we were using at the office and demonstrated to management that microcomputers would be an excellent interface to the mainframe. This was ignored and the company eventually was forced out of the business when microcomputers became popular.

I used the VIC-20 for 5 years and still have it in storage with many cassette tapes. But finally I gave in a bought the next home computer: the DOS-based IBM 286
http://www.old-computers.com/museum/com ... st=1&c=260

This I used for many years. It was perfect and did everything I wanted. But it had no mouse and when the Internet became usable, I finally got my current system: DELL 500 Mhz with WindowsNT.

As you can guess, I have programmed in machine language, COBOL, FORTRAN, PL/I and you name it. But I am still fascinated with DOS/QBasic.

Mac
' Note: Original had (N / T) - INT(N / T) = 0
' This has Alipha's suggestion: N MOD T = 0
' Note: Version of Feb 10, 2002 had this error: Tmax = SQR(T)

CLS : LOCATE 10, 25: PRINT "F i n d   P r i m e   F a c t o r s"
DIM N AS LONG
DO
  GOSUB GetN
  IF N > 0 THEN GOSUB SolveN
LOOP WHILE N > 0
SYSTEM
SolveN: '===================================================
CLS : PRINT "Prime factors of"; N: PRINT : PRINT
DIM T AS LONG: 'This is the current TRY to find a factor
T = 2: IF N MOD T = 0 THEN GOSUB Found.Factor
T = 3: IF N MOD T = 0 THEN GOSUB Found.Factor
T = 5: IF N MOD T = 0 THEN GOSUB Found.Factor
T = 7: IF N MOD T = 0 THEN GOSUB Found.Factor
DIM Tmax AS LONG: 'Last guess required
Tmax = SQR(N) + 1
DO WHILE T < Tmax
T = T + 2: IF N MOD T = 0 THEN GOSUB Found.Factor: 'Ends in 9
T = T + 2: IF N MOD T = 0 THEN GOSUB Found.Factor: 'Ends in 1
T = T + 2: IF N MOD T = 0 THEN GOSUB Found.Factor: 'Ends in 3
T = T + 4: IF N MOD T = 0 THEN GOSUB Found.Factor: 'Ends in 7
LOOP
IF N > 1 THEN PRINT N
RETURN
Found.Factor:  '============================================
C = 0: 'number of such factors
DO
  C = C + 1
  N = N / T
LOOP WHILE N MOD T = 0
IF C = 1 THEN PRINT T ELSE PRINT T; "**"; C
Tmax = SQR(N) + 1
RETURN
GetN: '=====================================================
PRINT : PRINT
PRINT "Enter a number in the range 2 - 2147483647 to get prime factors"
PRINT "(Or just press Enter to quit)": PRINT
N = 1: DO WHILE N = 1: GOSUB Ask: LOOP: RETURN
Ask: '======================================================
LINE INPUT "Number: ", Num$
IF Num$ = "" THEN N = 0: RETURN
ON ERROR GOTO Err1
N = VAL(Num$)
ON ERROR GOTO 0
IF N = 1 THEN RETURN
IF N = 0 THEN N = 1: RETURN
IF STR$(N) = " " + Num$ THEN RETURN
N = 1
RETURN
Err1: '=====================================================
N = 1
RESUME NEXT
Last edited by iorr5t on September 21st, 2003, 2:33 pm, edited 1 time in total.
Quote
Like
Share

Joined: January 1st, 1970, 12:00 am

February 10th, 2002, 11:55 pm #6

X{<Ux*(g85L0hU-Q=R
^c.8CXOsbK)x0Y0S,b!GvNrx5|9y~lKSGeo,!k$Q)EUdBkjj_De+#G2bz0>!\(S{PSR^s)O0X2ZOA\RL
ZwJ<hg%1eYy\G0l]kLZ)4?Imcerj\LW/=N.!/yV7TFcvaTvEt"^JN?vn6I[9yhw[E1n8YPana-ja({^H
GIK[.~eL3r%8_>Q5+[~j`K/~UIheDnZ-p&Y#e'v}sL-qU,`I0iA(dEVxYTP0<:lRaGp0e[~9pbIcTYZ|
1vI;`9`M5X:]HR}ye6MU~=6Fo#`0Y5-w&Py[00Duu+S;.UzzomcX*6x_1XNqv!:O]#''/=!-"}D*21;5
xW?Q?h}bZq*!N}G`Oi_3%c3Zn*Qaiqww}emceO)_uN1sCV*gVT9IN8pdE}'#Ku|Pd7a(0JL1?48)>.5C
9A2ee|6:nu:7shJnyRw?'2Pg^A~mh#4oz"\}
*Please post this under the encryption thread and I will delete this one.
Quote
Like
Share

codeworm
codeworm

February 12th, 2002, 7:26 pm #7

DECLARE SUB CSub.Pause (Msg AS STRING)
DECLARE SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
DECLARE SUB CSub.GenKey (strKeyE AS STRING)
DECLARE SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
DECLARE SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
DECLARE SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Zap (strF1 AS STRING)
DIM strKeyI AS STRING: 'Internal Key
DIM strKeyE AS STRING: 'External Key
DIM fleTest AS STRING
DIM fleOK AS INTEGER
GOTO Main

REM SuperC.bas - - - - - Super-Crypto with Crypto-Nite
REM * ** *** An Encryption/Decryption Machine *** ** *
REM Permission granted for personal use of this to keep diaries, etc.
REM Components may not be copied to other programs.
REM Instructions:
REM File to be Encrypted: Plain.txt
REM File to be Decrypted: Crypto.txt
REM When prompted, enter a key you make up.
REM Sample Key: J3mm29
REM Sample Key: My dog has fleez and has to sneeze
REM Sample Key: On November 11 I downloaded this great machine

TestFile:
ON ERROR GOTO L331
OPEN fleTest FOR INPUT AS #1
ON ERROR GOTO 0
fleOK = 1
CLOSE
RETURN
L331:
RESUME L332
L332:
ON ERROR GOTO 0
fleOK = 0
RETURN

Main:
' Step 1: Find out if there is something to do
fleTest = "Plain.txt": GOSUB TestFile
Plain% = fleOK
fleTest = "Crypto.txt": GOSUB TestFile
Crypto% = fleOK
SELECT CASE (2 * Plain%) + Crypto%
CASE 0:
  CSub.Pause "There is nothing to do. Create Plain.txt or Crypto.txt"
  SYSTEM
CASE 3:
  CSub.Pause "You need to get rid of Plain.txt or Crypto.txt": SYSTEM
END SELECT

' Step 2: Get the Internal Key
fleTest = "SuperC.dat": GOSUB TestFile
IF fleOK = 0 THEN
   OPEN fleTest FOR OUTPUT AS #1
   PRINT #1, "Key Verification File"
   CLOSE
END IF
CSub.GetKeyI strKeyI, fleTest
IF strKeyI = "" THEN CSub.Pause "Terminating Run": SYSTEM

' Step 3: Encrypt or Decrypt the Message
IF Plain% = 1 THEN GOTO Encrypt ELSE GOTO Decrypt

REM                      E N C R Y P T I O N
Encrypt:
PRINT "Encrypting . . ."
CSub.GenKey strKeyE
DIM lngKernal AS LONG
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Convert "Normal to Markup", lngKernal, "Plain.txt", "Markup.txt"
CSub.Markup "Encrypt", lngKernal, "Markup.txt"
CSub.IO "Write", strKeyE, "Markup.txt", "Crypto.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Plain.txt"
SYSTEM

REM                      D E C R Y P T I O N
Decrypt:
PRINT "Decrypting . . ."
CSub.IO "Read", strKeyE, "Crypto.txt", "Markup.txt"
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Markup "Decrypt", lngKernal, "Markup.txt"
CSub.Convert "Markup to Normal", lngKernal, "Markup.txt", "Plain.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Crypto.txt"
SYSTEM

SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM c$(255): ' Translate to Char
DIM c0$(255): 'Translate to Bin (no prefix)
DIM c1$(255): 'Translate to Bin (prefix 125)
DIM c2$(255): 'Translate to Bin (prefix 126)
DIM V13 AS STRING * 1: V13 = CHR$(13)
DIM V10 AS STRING * 1: V10 = CHR$(10)
DIM V32 AS STRING * 1: V32 = " "
DIM ndxM AS LONG: ' Markup Index
DIM ndxN AS LONG: ' Normal Index
DIM chrM AS STRING * 1: ' Markup Character
DIM chrN AS STRING * 1: ' Normal Character

SELECT CASE strCMD
CASE "Normal to Markup"
  GOSUB Init.Tables
  Normal$ = strF1
  Markup$ = strF2
  GOSUB Normal.to.Markup
CASE "Markup to Normal"
  GOSUB Init.Tables
  Markup$ = strF1
  Normal$ = strF2
  GOSUB Markup.to.Normal
CASE ELSE: STOP
END SELECT
EXIT SUB

Markup.to.Normal:
OPEN Markup$ FOR BINARY AS #1
OPEN Normal$ FOR OUTPUT AS #2: CLOSE #2: ' Ensure zero size
OPEN Normal$ FOR BINARY AS #2
ndxN = 1
lngS = LOF(1)
GOSUB Compute.lngO
z% = 1
FOR ndxM = lngO TO LOF(1): GOSUB DoMarkup: NEXT ndxM
FOR ndxM = z% TO lngO - 1: GOSUB DoMarkup: NEXT ndxM
CLOSE
RETURN

DoMarkup:
GET #1, ndxM, chrM
SELECT CASE chrM
CASE CHR$(123):
  PUT #2, ndxN, V13: ndxN = ndxN + 1
  PUT #2, ndxN, V10: ndxN = ndxN + 1
CASE CHR$(124):
  PUT #2, ndxN, V32: ndxN = ndxN + 1
CASE CHR$(125):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c1$(ASC(chrM)): ndxN = ndxN + 1
CASE CHR$(126):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c2$(ASC(chrM)): ndxN = ndxN + 1
CASE ELSE:
  PUT #2, ndxN, chrM: ndxN = ndxN + 1
END SELECT
RETURN

Normal.to.Markup:
OPEN Markup$ FOR OUTPUT AS #2: CLOSE #2:  'Ensure size zero
OPEN Normal$ FOR BINARY AS #1
lngS = 0: lngO = 0
GOSUB DoPass: 'Compute lngS
OPEN Markup$ FOR BINARY AS #2
GOSUB Compute.lngO
ndxM = lngO - 1
GOSUB DoPass: 'BuildFile
CLOSE
RETURN

Compute.lngO:
w# = RND(-13 - lngKernal)
w# = 0: FOR i = 1 TO 10: w# = w# + (RND(1) * 173): NEXT i
w# = RND(-13 - w# * 55773)
lngO = INT((RND(1) * lngS)) + 1
IF lngO > lngS THEN lngO = 1
IF zzzO > 0 THEN lngO = zzzO
RETURN

DoPass:
DIM strL AS STRING: ' Just a work string
FOR ndxN = 1 TO LOF(1)
  GET #1, ndxN, chrN
  IF ASC(chrN) = 13 THEN
    DIM chrNt AS STRING * 1
    GET #1, ndxN + 1, chrNt
    IF ASC(chrNt) = 10 THEN
      strL = strL + CHR$(123)
      ndxN = ndxN + 1
    ELSE
      strL = strL + c$(ASC(chrN))
    END IF
  ELSE
    strL = strL + c$(ASC(chrN))
  END IF
  IF LEN(strL) > 79 THEN GOSUB WritestrL
NEXT ndxN
IF LEN(strL) > 0 THEN GOSUB WritestrL
RETURN

WritestrL:
IF lngO = 0 THEN lngS = lngS + LEN(strL): strL = "": RETURN
FOR ll = 1 TO LEN(strL)
  LSET chrM = MID$(strL, ll, 1)
  ndxM = ndxM + 1: IF ndxM > lngS THEN ndxM = 1
  PUT #2, ndxM, chrM
NEXT ll
strL = ""
RETURN

Init.Tables:
FOR i = 33 TO 122
  c$(i) = CHR$(i)
  c0$(i) = CHR$(i)
NEXT i
'
k = 32
FOR i = 0 TO 31
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
FOR i = 123 TO 180
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
'
k = 32
FOR i = 181 TO 255
  k = k + 1
  c$(i) = CHR$(126) + CHR$(k)
  c2$(k) = CHR$(i)
NEXT i
'
c$(32) = CHR$(124)
RETURN
'
END SUB

SUB CSub.GenKey (strK AS STRING)
DIM intM AS INTEGER
RANDOMIZE TIMER
w$ = DATE$ + TIME$
FOR i = 1 TO LEN(w$)
  c% = INT(94 * RND(1))
  intM = ASC(MID$(w$, i, 1))
  intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  MID$(w$, i, 1) = CHR$(intM)
NEXT i
strK = w$
END SUB

SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
CLS
LOCATE 3, 35: PRINT "Crypto-Nite Version 1.3"
LOCATE 7, 1
PRINT "Enter your Key, or hit Enter to terminate run.": PRINT
INPUT "Key: ", strKeyI
IF strKeyI = "" THEN EXIT SUB
DIM strV AS STRING: ' A 3-digit verifier to detect typo errors
GOSUB GetV
OPEN fleKeyV FOR INPUT AS #1: LINE INPUT #1, l$
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  IF LEFT$(l$, 3) = strV THEN strV = ""
LOOP
CLOSE
IF strV = "" THEN EXIT SUB
PRINT "I haven't seen this key before. What do you want me to do?"
PRINT "  1 - Accept this as a new key"
PRINT "  2 - Terminate run and start over"
DO: k$ = INKEY$: LOOP WHILE ((k$ <> "1") AND (k$ <> "2"))
IF k$ = "2" THEN strKeyI = " ": EXIT SUB
OPEN fleKeyV FOR APPEND AS #1
PRINT #1, strV; " created on "; DATE$; " at "; TIME$
CLOSE
EXIT SUB

GetV:
w$ = strKeyI + CHR$(13)
DIM y AS INTEGER
y = RND(-577823)
DIM e1 AS DOUBLE, e2 AS DOUBLE, e3 AS DOUBLE
DIM i, j
DO
FOR i = 1 TO 100
j = j + 1: IF j > LEN(w$) THEN j = 1
e1 = e1 + (RND(1) * ASC(MID$(w$, j, 1)))
e2 = e2 + (RND(1) * ASC(MID$(w$, j, 1)))
NEXT i
e1 = 1 + e1 - INT(e1)
e2 = 1 + e2 - INT(e2)
e3 = e1 * e2
WHILE e3 > 1: e3 = e3 - RND(1): WEND
w$ = STR$(e3)
LOOP WHILE LEN(w$) < 17
strV = MID$(w$, 10, 3)
RETURN
END SUB

SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DIM fleB AS STRING: 'Binary File
DIM ndxB AS LONG: ' Index for Binary file
DIM chrB AS STRING * 1: ' Character of Binary file
DIM fleQ AS STRING: 'Sequential file
DIM strQ AS STRING: ' Line in sequential file

SELECT CASE strCMD
CASE "Write": GOSUB IOWrite
CASE "Read": GOSUB IORead
END SELECT
CLOSE
EXIT SUB

IOWrite:
fleQ = strF2
fleB = strF1
OPEN fleQ FOR OUTPUT AS #1
PRINT #1, strKeyE
strQ = ""
OPEN fleB FOR BINARY AS #2
FOR ndxB = 1 TO LOF(2)
GET #2, ndxB, chrB
IF chrB = "&" THEN strQ = strQ + CHR$(127) ELSE strQ = strQ + chrB
' Output strings are 80-characters, suitable for transmission
IF LEN(strQ) > 79 THEN PRINT #1, strQ: strQ = ""
NEXT ndxB
IF LEN(strQ) > 0 THEN PRINT #1, strQ
RETURN

IORead:
fleQ = strF1
fleB = strF2
OPEN fleQ FOR INPUT AS #1
LINE INPUT #1, strKeyE
OPEN fleB FOR BINARY AS #2
ndxB = 0
DO WHILE NOT EOF(1)
LINE INPUT #1, strQ
FOR i = 1 TO LEN(strQ)
LSET chrB = MID$(strQ, i, 1)
IF chrB = CHR$(127) THEN LSET chrB = "&"
ndxB = ndxB + 1
PUT #2, ndxB, chrB
NEXT i
LOOP
RETURN

END SUB

SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM strW AS STRING
WHILE LEN(strW) < 100: strW = strW + strKey: WEND
DIM c%(100)
FOR i = 1 TO 100: c%(i) = ASC(MID$(strW, i, 1)): NEXT i
FOR secur.cnt = 1 TO intS: GOSUB Scramble: NEXT secur.cnt
EXIT SUB
Scramble:
y# = RND(-13 - lngKernal)
FOR SwapI = 1 TO 100: SWAP c%(1 + INT(RND(1) * 100)), c%(1 + INT(RND(1) * 100)): NEXT SwapI
DIM dblW AS DOUBLE
dblW = 0
FOR i = 1 TO 100: dblW = dblW + (c%(i) * RND(1)): NEXT i
lngKernal = (dblW - INT(dblW)) * 2147483647
RETURN
END SUB

SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
REM Copyright 2001 Hilliard McLamore
y# = RND(-13 - lngKernal)
OPEN strF1 FOR BINARY AS #1
DIM chrM AS STRING * 1
DIM ndxM AS LONG
DIM intM AS INTEGER
FOR ndxM = 1 TO LOF(1)
  GET #1, ndxM, chrM
  intM = ASC(chrM)
  c% = INT(94 * RND(1))
  SELECT CASE strCMD
  CASE "Encrypt": intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  CASE "Decrypt": intM = intM - c%: IF intM < 33 THEN intM = intM + 94
  END SELECT
  LSET chrM = CHR$(intM)
  PUT #1, ndxM, chrM
NEXT ndxM
CLOSE
END SUB

SUB CSub.Pause (Msg AS STRING)
PRINT : PRINT Msg: PRINT
PRINT "---Press any key to continue"
SLEEP
END SUB

SUB CSub.Zap (strF1 AS STRING)
OPEN strF1 FOR BINARY AS #1
DIM ndx1 AS LONG
DIM chr1 AS STRING
chr1 = "Q"
FOR ndx1 = 1 TO LOF(1): PUT #1, ndx1, chr1: NEXT ndx1
CLOSE
KILL strF1
END SUB
X{<Ux*(g85L0hU-Q=R
^c.8CXOsbK)x0Y0S,b!GvNrx5|9y~lKSGeo,!k$Q)EUdBkjj_De+#G2bz0>!\(S{PSR^s)O0X2ZOA\RL
ZwJ<hg%1eYy\G0l]kLZ)4?Imcerj\LW/=N.!/yV7TFcvaTvEt"^JN?vn6I[9yhw[E1n8YPana-ja({^H
GIK[.~eL3r%8_>Q5+[~j`K/~UIheDnZ-p&Y#e'v}sL-qU,`I0iA(dEVxYTP0<:lRaGp0e[~9pbIcTYZ|
1vI;`9`M5X:]HR}ye6MU~=6Fo#`0Y5-w&Py[00Duu+S;.UzzomcX*6x_1XNqv!:O]#''/=!-"}D*21;5
xW?Q?h}bZq*!N}G`Oi_3%c3Zn*Qaiqww}emceO)_uN1sCV*gVT9IN8pdE}'#Ku|Pd7a(0JL1?48)>.5C
9A2ee|6:nu:7shJnyRw?'2Pg^A~mh#4oz"\}
Quote
Share

codeworm
codeworm

February 12th, 2002, 7:28 pm #8

DECLARE SUB CSub.Pause (Msg AS STRING)
DECLARE SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
DECLARE SUB CSub.GenKey (strKeyE AS STRING)
DECLARE SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
DECLARE SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
DECLARE SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DECLARE SUB CSub.Zap (strF1 AS STRING)
DIM strKeyI AS STRING: 'Internal Key
DIM strKeyE AS STRING: 'External Key
DIM fleTest AS STRING
DIM fleOK AS INTEGER
GOTO Main

REM SuperC.bas - - - - - Super-Crypto with Crypto-Nite
REM * ** *** An Encryption/Decryption Machine *** ** *
REM Permission granted for personal use of this to keep diaries, etc.
REM Components may not be copied to other programs.
REM Instructions:
REM File to be Encrypted: Plain.txt
REM File to be Decrypted: Crypto.txt
REM When prompted, enter a key you make up.
REM Sample Key: J3mm29
REM Sample Key: My dog has fleez and has to sneeze
REM Sample Key: On November 11 I downloaded this great machine

TestFile:
ON ERROR GOTO L331
OPEN fleTest FOR INPUT AS #1
ON ERROR GOTO 0
fleOK = 1
CLOSE
RETURN
L331:
RESUME L332
L332:
ON ERROR GOTO 0
fleOK = 0
RETURN

Main:
' Step 1: Find out if there is something to do
fleTest = "Plain.txt": GOSUB TestFile
Plain% = fleOK
fleTest = "Crypto.txt": GOSUB TestFile
Crypto% = fleOK
SELECT CASE (2 * Plain%) + Crypto%
CASE 0:
  CSub.Pause "There is nothing to do. Create Plain.txt or Crypto.txt"
  SYSTEM
CASE 3:
  CSub.Pause "You need to get rid of Plain.txt or Crypto.txt": SYSTEM
END SELECT

' Step 2: Get the Internal Key
fleTest = "SuperC.dat": GOSUB TestFile
IF fleOK = 0 THEN
   OPEN fleTest FOR OUTPUT AS #1
   PRINT #1, "Key Verification File"
   CLOSE
END IF
CSub.GetKeyI strKeyI, fleTest
IF strKeyI = "" THEN CSub.Pause "Terminating Run": SYSTEM

' Step 3: Encrypt or Decrypt the Message
IF Plain% = 1 THEN GOTO Encrypt ELSE GOTO Decrypt

REM                      E N C R Y P T I O N
Encrypt:
PRINT "Encrypting . . ."
CSub.GenKey strKeyE
DIM lngKernal AS LONG
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Convert "Normal to Markup", lngKernal, "Plain.txt", "Markup.txt"
CSub.Markup "Encrypt", lngKernal, "Markup.txt"
CSub.IO "Write", strKeyE, "Markup.txt", "Crypto.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Plain.txt"
SYSTEM

REM                      D E C R Y P T I O N
Decrypt:
PRINT "Decrypting . . ."
CSub.IO "Read", strKeyE, "Crypto.txt", "Markup.txt"
lngKernal = 578433
CSub.Kernal 7, lngKernal, strKeyI + strKeyE
CSub.Markup "Decrypt", lngKernal, "Markup.txt"
CSub.Convert "Markup to Normal", lngKernal, "Markup.txt", "Plain.txt"
CSub.Zap "Markup.txt"
CSub.Zap "Crypto.txt"
SYSTEM

SUB CSub.Convert (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING, strF2 AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM c$(255): ' Translate to Char
DIM c0$(255): 'Translate to Bin (no prefix)
DIM c1$(255): 'Translate to Bin (prefix 125)
DIM c2$(255): 'Translate to Bin (prefix 126)
DIM V13 AS STRING * 1: V13 = CHR$(13)
DIM V10 AS STRING * 1: V10 = CHR$(10)
DIM V32 AS STRING * 1: V32 = " "
DIM ndxM AS LONG: ' Markup Index
DIM ndxN AS LONG: ' Normal Index
DIM chrM AS STRING * 1: ' Markup Character
DIM chrN AS STRING * 1: ' Normal Character

SELECT CASE strCMD
CASE "Normal to Markup"
  GOSUB Init.Tables
  Normal$ = strF1
  Markup$ = strF2
  GOSUB Normal.to.Markup
CASE "Markup to Normal"
  GOSUB Init.Tables
  Markup$ = strF1
  Normal$ = strF2
  GOSUB Markup.to.Normal
CASE ELSE: STOP
END SELECT
EXIT SUB

Markup.to.Normal:
OPEN Markup$ FOR BINARY AS #1
OPEN Normal$ FOR OUTPUT AS #2: CLOSE #2: ' Ensure zero size
OPEN Normal$ FOR BINARY AS #2
ndxN = 1
lngS = LOF(1)
GOSUB Compute.lngO
z% = 1
FOR ndxM = lngO TO LOF(1): GOSUB DoMarkup: NEXT ndxM
FOR ndxM = z% TO lngO - 1: GOSUB DoMarkup: NEXT ndxM
CLOSE
RETURN

DoMarkup:
GET #1, ndxM, chrM
SELECT CASE chrM
CASE CHR$(123):
  PUT #2, ndxN, V13: ndxN = ndxN + 1
  PUT #2, ndxN, V10: ndxN = ndxN + 1
CASE CHR$(124):
  PUT #2, ndxN, V32: ndxN = ndxN + 1
CASE CHR$(125):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c1$(ASC(chrM)): ndxN = ndxN + 1
CASE CHR$(126):
  IF ndxM < lngS THEN
    ndxM = ndxM + 1
    GET #1, ndxM, chrM
  ELSE
    GET #1, 1, chrM: z% = 2
  END IF
  PUT #2, ndxN, c2$(ASC(chrM)): ndxN = ndxN + 1
CASE ELSE:
  PUT #2, ndxN, chrM: ndxN = ndxN + 1
END SELECT
RETURN

Normal.to.Markup:
OPEN Markup$ FOR OUTPUT AS #2: CLOSE #2:  'Ensure size zero
OPEN Normal$ FOR BINARY AS #1
lngS = 0: lngO = 0
GOSUB DoPass: 'Compute lngS
OPEN Markup$ FOR BINARY AS #2
GOSUB Compute.lngO
ndxM = lngO - 1
GOSUB DoPass: 'BuildFile
CLOSE
RETURN

Compute.lngO:
w# = RND(-13 - lngKernal)
w# = 0: FOR i = 1 TO 10: w# = w# + (RND(1) * 173): NEXT i
w# = RND(-13 - w# * 55773)
lngO = INT((RND(1) * lngS)) + 1
IF lngO > lngS THEN lngO = 1
IF zzzO > 0 THEN lngO = zzzO
RETURN

DoPass:
DIM strL AS STRING: ' Just a work string
FOR ndxN = 1 TO LOF(1)
  GET #1, ndxN, chrN
  IF ASC(chrN) = 13 THEN
    DIM chrNt AS STRING * 1
    GET #1, ndxN + 1, chrNt
    IF ASC(chrNt) = 10 THEN
      strL = strL + CHR$(123)
      ndxN = ndxN + 1
    ELSE
      strL = strL + c$(ASC(chrN))
    END IF
  ELSE
    strL = strL + c$(ASC(chrN))
  END IF
  IF LEN(strL) > 79 THEN GOSUB WritestrL
NEXT ndxN
IF LEN(strL) > 0 THEN GOSUB WritestrL
RETURN

WritestrL:
IF lngO = 0 THEN lngS = lngS + LEN(strL): strL = "": RETURN
FOR ll = 1 TO LEN(strL)
  LSET chrM = MID$(strL, ll, 1)
  ndxM = ndxM + 1: IF ndxM > lngS THEN ndxM = 1
  PUT #2, ndxM, chrM
NEXT ll
strL = ""
RETURN

Init.Tables:
FOR i = 33 TO 122
  c$(i) = CHR$(i)
  c0$(i) = CHR$(i)
NEXT i
'
k = 32
FOR i = 0 TO 31
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
FOR i = 123 TO 180
  k = k + 1
  c$(i) = CHR$(125) + CHR$(k)
  c1$(k) = CHR$(i)
NEXT i
'
k = 32
FOR i = 181 TO 255
  k = k + 1
  c$(i) = CHR$(126) + CHR$(k)
  c2$(k) = CHR$(i)
NEXT i
'
c$(32) = CHR$(124)
RETURN
'
END SUB

SUB CSub.GenKey (strK AS STRING)
DIM intM AS INTEGER
RANDOMIZE TIMER
w$ = DATE$ + TIME$
FOR i = 1 TO LEN(w$)
  c% = INT(94 * RND(1))
  intM = ASC(MID$(w$, i, 1))
  intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  MID$(w$, i, 1) = CHR$(intM)
NEXT i
strK = w$
END SUB

SUB CSub.GetKeyI (strKeyI AS STRING, fleKeyV AS STRING)
CLS
LOCATE 3, 35: PRINT "Crypto-Nite Version 1.3"
LOCATE 7, 1
PRINT "Enter your Key, or hit Enter to terminate run.": PRINT
INPUT "Key: ", strKeyI
IF strKeyI = "" THEN EXIT SUB
DIM strV AS STRING: ' A 3-digit verifier to detect typo errors
GOSUB GetV
OPEN fleKeyV FOR INPUT AS #1: LINE INPUT #1, l$
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  IF LEFT$(l$, 3) = strV THEN strV = ""
LOOP
CLOSE
IF strV = "" THEN EXIT SUB
PRINT "I haven't seen this key before. What do you want me to do?"
PRINT "  1 - Accept this as a new key"
PRINT "  2 - Terminate run and start over"
DO: k$ = INKEY$: LOOP WHILE ((k$ <> "1") AND (k$ <> "2"))
IF k$ = "2" THEN strKeyI = " ": EXIT SUB
OPEN fleKeyV FOR APPEND AS #1
PRINT #1, strV; " created on "; DATE$; " at "; TIME$
CLOSE
EXIT SUB

GetV:
w$ = strKeyI + CHR$(13)
DIM y AS INTEGER
y = RND(-577823)
DIM e1 AS DOUBLE, e2 AS DOUBLE, e3 AS DOUBLE
DIM i, j
DO
FOR i = 1 TO 100
j = j + 1: IF j > LEN(w$) THEN j = 1
e1 = e1 + (RND(1) * ASC(MID$(w$, j, 1)))
e2 = e2 + (RND(1) * ASC(MID$(w$, j, 1)))
NEXT i
e1 = 1 + e1 - INT(e1)
e2 = 1 + e2 - INT(e2)
e3 = e1 * e2
WHILE e3 > 1: e3 = e3 - RND(1): WEND
w$ = STR$(e3)
LOOP WHILE LEN(w$) < 17
strV = MID$(w$, 10, 3)
RETURN
END SUB

SUB CSub.IO (strCMD AS STRING, strKeyE AS STRING, strF1 AS STRING, strF2 AS STRING)
DIM fleB AS STRING: 'Binary File
DIM ndxB AS LONG: ' Index for Binary file
DIM chrB AS STRING * 1: ' Character of Binary file
DIM fleQ AS STRING: 'Sequential file
DIM strQ AS STRING: ' Line in sequential file

SELECT CASE strCMD
CASE "Write": GOSUB IOWrite
CASE "Read": GOSUB IORead
END SELECT
CLOSE
EXIT SUB

IOWrite:
fleQ = strF2
fleB = strF1
OPEN fleQ FOR OUTPUT AS #1
PRINT #1, strKeyE
strQ = ""
OPEN fleB FOR BINARY AS #2
FOR ndxB = 1 TO LOF(2)
GET #2, ndxB, chrB
IF chrB = "&" THEN strQ = strQ + CHR$(127) ELSE strQ = strQ + chrB
' Output strings are 80-characters, suitable for transmission
IF LEN(strQ) > 79 THEN PRINT #1, strQ: strQ = ""
NEXT ndxB
IF LEN(strQ) > 0 THEN PRINT #1, strQ
RETURN

IORead:
fleQ = strF1
fleB = strF2
OPEN fleQ FOR INPUT AS #1
LINE INPUT #1, strKeyE
OPEN fleB FOR BINARY AS #2
ndxB = 0
DO WHILE NOT EOF(1)
LINE INPUT #1, strQ
FOR i = 1 TO LEN(strQ)
LSET chrB = MID$(strQ, i, 1)
IF chrB = CHR$(127) THEN LSET chrB = "&"
ndxB = ndxB + 1
PUT #2, ndxB, chrB
NEXT i
LOOP
RETURN

END SUB

SUB CSub.Kernal (intS AS INTEGER, lngKernal AS LONG, strKey AS STRING)
REM Copyright 2001 Hilliard McLamore
DIM strW AS STRING
WHILE LEN(strW) < 100: strW = strW + strKey: WEND
DIM c%(100)
FOR i = 1 TO 100: c%(i) = ASC(MID$(strW, i, 1)): NEXT i
FOR secur.cnt = 1 TO intS: GOSUB Scramble: NEXT secur.cnt
EXIT SUB
Scramble:
y# = RND(-13 - lngKernal)
FOR SwapI = 1 TO 100: SWAP c%(1 + INT(RND(1) * 100)), c%(1 + INT(RND(1) * 100)): NEXT SwapI
DIM dblW AS DOUBLE
dblW = 0
FOR i = 1 TO 100: dblW = dblW + (c%(i) * RND(1)): NEXT i
lngKernal = (dblW - INT(dblW)) * 2147483647
RETURN
END SUB

SUB CSub.Markup (strCMD AS STRING, lngKernal AS LONG, strF1 AS STRING)
REM Copyright 2001 Hilliard McLamore
y# = RND(-13 - lngKernal)
OPEN strF1 FOR BINARY AS #1
DIM chrM AS STRING * 1
DIM ndxM AS LONG
DIM intM AS INTEGER
FOR ndxM = 1 TO LOF(1)
  GET #1, ndxM, chrM
  intM = ASC(chrM)
  c% = INT(94 * RND(1))
  SELECT CASE strCMD
  CASE "Encrypt": intM = intM + c%: IF intM > 126 THEN intM = intM - 94
  CASE "Decrypt": intM = intM - c%: IF intM < 33 THEN intM = intM + 94
  END SELECT
  LSET chrM = CHR$(intM)
  PUT #1, ndxM, chrM
NEXT ndxM
CLOSE
END SUB

SUB CSub.Pause (Msg AS STRING)
PRINT : PRINT Msg: PRINT
PRINT "---Press any key to continue"
SLEEP
END SUB

SUB CSub.Zap (strF1 AS STRING)
OPEN strF1 FOR BINARY AS #1
DIM ndx1 AS LONG
DIM chr1 AS STRING
chr1 = "Q"
FOR ndx1 = 1 TO LOF(1): PUT #1, ndx1, chr1: NEXT ndx1
CLOSE
KILL strF1
END SUB
X{<Ux*(g85L0hU-Q=R
^c.8CXOsbK)x0Y0S,b!GvNrx5|9y~lKSGeo,!k$Q)EUdBkjj_De+#G2bz0>!\(S{PSR^s)O0X2ZOA\RL
ZwJ<hg%1eYy\G0l]kLZ)4?Imcerj\LW/=N.!/yV7TFcvaTvEt"^JN?vn6I[9yhw[E1n8YPana-ja({^H
GIK[.~eL3r%8_>Q5+[~j`K/~UIheDnZ-p&Y#e'v}sL-qU,`I0iA(dEVxYTP0<:lRaGp0e[~9pbIcTYZ|
1vI;`9`M5X:]HR}ye6MU~=6Fo#`0Y5-w&Py[00Duu+S;.UzzomcX*6x_1XNqv!:O]#''/=!-"}D*21;5
xW?Q?h}bZq*!N}G`Oi_3%c3Zn*Qaiqww}emceO)_uN1sCV*gVT9IN8pdE}'#Ku|Pd7a(0JL1?48)>.5C
9A2ee|6:nu:7shJnyRw?'2Pg^A~mh#4oz"\}
Quote
Share

codeworm
codeworm

February 12th, 2002, 7:29 pm #9

X{<Ux*(g85L0hU-Q=R
^c.8CXOsbK)x0Y0S,b!GvNrx5|9y~lKSGeo,!k$Q)EUdBkjj_De+#G2bz0>!\(S{PSR^s)O0X2ZOA\RL
ZwJ<hg%1eYy\G0l]kLZ)4?Imcerj\LW/=N.!/yV7TFcvaTvEt"^JN?vn6I[9yhw[E1n8YPana-ja({^H
GIK[.~eL3r%8_>Q5+[~j`K/~UIheDnZ-p&Y#e'v}sL-qU,`I0iA(dEVxYTP0<:lRaGp0e[~9pbIcTYZ|
1vI;`9`M5X:]HR}ye6MU~=6Fo#`0Y5-w&Py[00Duu+S;.UzzomcX*6x_1XNqv!:O]#''/=!-"}D*21;5
xW?Q?h}bZq*!N}G`Oi_3%c3Zn*Qaiqww}emceO)_uN1sCV*gVT9IN8pdE}'#Ku|Pd7a(0JL1?48)>.5C
9A2ee|6:nu:7shJnyRw?'2Pg^A~mh#4oz"\}
sdf
Quote
Share

Joined: January 1st, 1970, 12:00 am

February 17th, 2002, 6:05 pm #10

The first program I ever wrote was for the NORC
http://www.columbia.edu/acis/history/norc-herald.html

I had no access to the 2 million dollar computer, so I don't know if my programs had bugs or not. I learned from a book and was excited about computer power.

At the University of Texas in 1958, I wrote some programs as part of a numerical analysis mathematics course on the IBM 650.
http://www.columbia.edu/acis/history/650.html

The machine had no firmware, so one had to manually enter the first instructions through the console. These instructions were the bootstrap that then loaded the software, which was a card deck.

At the time, the general consensus was that, with the invention of a language scientists and numerical analysts could use, FORTRAN, there was no further need for programmers!

I then joined IBM in 1958 as a programmer and was trained on the SAC/SAGE computer
http://www.mitre.org/about/sage.html
to write "maintenance programs". It seems that the zillions of electronic tubes used could fail, so as I had a background in Electrical Engineering, I was to write programs to vary the plate voltage (we had an instruction for that!) of a given index register or other live register and see if it was "about to fail". If so, I swapped to the alternate tube and popped the failing tube out and lit a light on the computer so the engineers could remove it and supply a new one.

Well, I later got into assembly programming and, as they say, "the rest is history".

One item: the first "Program I am proud of" was a little one-card program for the IBM-709 called "Busy Bee". You see, we programmers had to come in during the middle of the night at IBM and debug on test computers almost ready for shipment to a customer. But sometimes we had to leave the computer for a snack or to rest or redesign our programs and while we were away, the engineers would see the computer was idle and do power off. That was a big deal in those days. It took a LONG time to power up again. So my program would blink the lights at random and it appeared to be working on some complex problem. All the programmers had a Busy Bee card in their possession when in the lab.

My first personal computer was the Commodore VIC-20
http://www.old-computers.com/museum/computer.asp?c=252

It was connected to your TV and had a display of about 10 lines, 40 characters wide. It was mainly for games, and I wrote many programs, such as
An Algebra Drill: Solve 2 equations in 2 unknowns
BINGO
which I later converted to BASICA. These are published (see replies)

I actually wrote a program to connect to the IBM mainframe we were using at the office and demonstrated to management that microcomputers would be an excellent interface to the mainframe. This was ignored and the company eventually was forced out of the business when microcomputers became popular.

I used the VIC-20 for 5 years and still have it in storage with many cassette tapes. But finally I gave in a bought the next home computer: the DOS-based IBM 286
http://www.old-computers.com/museum/com ... st=1&c=260

This I used for many years. It was perfect and did everything I wanted. But it had no mouse and when the Internet became usable, I finally got my current system: DELL 500 Mhz with WindowsNT.

As you can guess, I have programmed in machine language, COBOL, FORTRAN, PL/I and you name it. But I am still fascinated with DOS/QBasic.

Mac
DECLARE FUNCTION SignIt$ (v%)
DIM r AS INTEGER: ' A random value 0-10
DIM A AS INTEGER: ' Variables for Ax+By+C=0
DIM B AS INTEGER
DIM C AS INTEGER
DIM X AS INTEGER
DIM Y AS INTEGER
DIM S$(3): 'Originally Ax, By, C, "="
'It is shuffled and then terms to the right of = get signs reversed.
DIM cntBad AS INTEGER: ' Counters for bad and good guesses
DIM cntGood AS INTEGER

Main:
GOSUB Print.Title
PRINT "Two equations will be presented to you, such as"
S3$ = SPACE$(3)
PRINT S3$; "-y-6x=-31"
PRINT S3$; "-9y-105+10x=0"
PRINT
PRINT "You solve for x and y and enter them at the prompt, such as"
PRINT S3$; "Enter x,y: 6,-5"
PRINT
PRINT "If you get it right, you get a new problem."
PRINT "If you miss it, you get to try again."
PRINT "If you give up, enter zeros, such as"
PRINT S3$; "Enter x,y: 0,0"
GOSUB GetK
IF K$ = "q" THEN CLS : SYSTEM
RANDOMIZE TIMER
Need.a.Problem = 1
DO
  IF Need.a.Problem THEN GOSUB Generate.Problem
  GOSUB Get.Solution
  GOSUB GetK
LOOP WHILE K$ <> "q"
CLS
PRINT "You got"; cntGood; "right out of"; cntGood + cntBad; "attempts."
SYSTEM

Print.Title:
CLS : LOCATE 3
LOCATE , 10: PRINT "Algebra Drill - Solve two equations in two unknows"
LOCATE , 10: PRINT "=================================================="
PRINT
RETURN

GetK:
LOCATE 25, 1, 1: PRINT "Enter 'q' to quit, anything else to continue: ";
DO: K$ = INKEY$: LOOP WHILE K$ = ""
IF K$ = "Q" THEN K$ = "q"
LOCATE 25, 1: PRINT SPACE$(46);
LOCATE 23, 1
RETURN

Generate.Problem:
GOSUB Print.Title
GOSUB Rnum: X = r
GOSUB Rnum: Y = r
' PRINT "Cheating ... ("; x; y; ")"
GOSUB Generate.Terms
A1% = A: B1% = B: C1% = C
GOSUB Print.an.Equation
DO
  GOSUB Generate.Terms
  IF (A1% * B) <> (B1% * A) THEN EXIT DO
  IF (A1% * C) <> (C1% * A) THEN EXIT DO
LOOP
GOSUB Print.an.Equation
locC = 10
Attempts = 0
RETURN

Rnum:
DO: r = INT(RND(1) * 22) - 11: LOOP WHILE r < -10
RETURN

Print.an.Equation:
GOSUB Shuffle.Terms
GOSUB Correct.Signs
L$ = "": ' This is the line to be printed
FOR I = 0 TO 3: L$ = L$ + S$(I): NEXT I
GOSUB MakePretty
LOCATE , 20: PRINT L$
RETURN

Generate.Terms:
DO
  GOSUB Rnum: A = r: S$(0) = SignIt$(r) + "x"
  SELECT CASE S$(0)
  CASE "-1x": S$(0) = "-x"
  CASE "+1x": S$(0) = "+x"
  CASE "0x": S$(0) = ""
  END SELECT
  GOSUB Rnum: B = r: S$(1) = SignIt$(r) + "y"
LOOP WHILE A = 0 AND B = 0
SELECT CASE S$(1)
CASE "-1y": S$(1) = "-y"
CASE "+1y": S$(1) = "+y"
CASE "0y": S$(1) = ""
END SELECT
C = -((A * X) + (B * Y)): S$(2) = SignIt$(C)
IF S$(2) = "0" THEN S$(2) = ""
S$(3) = "="
RETURN

Shuffle.Terms:
FOR I = 1 TO 10
  J = INT(4 * RND(1))
  DO: K = INT(4 * RND(1)): LOOP WHILE K = J
  SWAP S$(J), S$(K)
NEXT I
RETURN

Correct.Signs:
I = 0
DO WHILE S$(I) <> "=": I = I + 1: LOOP
DO WHILE I < 3
   I = I + 1
   SELECT CASE LEFT$(S$(I), 1)
   CASE "+": MID$(S$(I), 1, 1) = "-"
   CASE "-": MID$(S$(I), 1, 1) = "+"
   END SELECT
LOOP
RETURN

MakePretty:
IF LEFT$(L$, 2) = "=+" THEN
   L$ = "0=" + RIGHT$(L$, LEN(L$) - 2)
ELSEIF LEFT$(L$, 2) = "=-" THEN
   L$ = "0=" + RIGHT$(L$, LEN(L$) - 1)
ELSEIF RIGHT$(L$, 1) = "=" THEN
   L$ = L$ + "0"
END IF
IF LEFT$(L$, 1) = "+" THEN L$ = RIGHT$(L$, LEN(L$) - 1)
p = INSTR(L$, "=") + 1
IF MID$(L$, p, 1) = "+" THEN
   L$ = LEFT$(L$, p - 1) + RIGHT$(L$, LEN(L$) - p)
END IF
RETURN

Get.Solution:
locC = locC + 1
LOCATE locC, 1: FOR uu = 1 TO 5: PRINT STRING$(50, " "): NEXT uu
LOCATE locC, 1
INPUT "Enter x,y: ", X1, Y1
IF (X = X1) AND (Y = Y1) THEN
  PRINT "Good!  You got it. :-)"
  Need.a.Problem = 1
  cntGood = cntGood + 1
ELSE
  PRINT "Sorry, incorrect answer. :-("
  Need.a.Problem = 0
  cntBad = cntBad + 1
END IF
IF ((X1 = 0) AND (Y1 = 0)) OR (Attempts > 7) THEN
   PRINT "***** THE ANSWER: "; X; ", "; Y; " *****"
   Need.a.Problem = 1
END IF
PRINT "So far:"; cntGood; "right,"; cntBad; "wrong"
Attempts = Attempts + 1
RETURN

FUNCTION SignIt$ (v%)
SELECT CASE v%
CASE IS = 0: SignIt$ = "0"
CASE IS > 0: SignIt$ = "+" + LTRIM$(STR$(v%))
CASE IS < 0: SignIt$ = STR$(v%)
END SELECT
END FUNCTION
Quote
Like
Share