03-22-2003, 03:25 AM
Damn... if it is getting that tricky then it probably isn't a problem for newbies... :???: :???: I don't understand what is happening in there. The way I calculate pi is like this: pi = 4 * ATN(1). This is pi exactly but can only be printed to 15 s.f.
Mofu, have you solved it?
Or Neo???
ps: when I tried to modify your prog to calculate pi to 10000 places someone42, it started printing zeroes after a while. What have I done wrong? Or is it a message from aliens.. :rotfl:
I can make a program that prints its source in 4 lines, but it uses files... )
Here is a program that encrypts a string, and can decrypt it again. Any queries, suggestions etc I would appreciate
Mofu, have you solved it?
Or Neo???
ps: when I tried to modify your prog to calculate pi to 10000 places someone42, it started printing zeroes after a while. What have I done wrong? Or is it a message from aliens.. :rotfl:
I can make a program that prints its source in 4 lines, but it uses files... )
Here is a program that encrypts a string, and can decrypt it again. Any queries, suggestions etc I would appreciate
Code:
' -- Encryption Program --
' - By The Oracle -
' This program takes an inputted string and encodes it to a file. You can
' also use this program to decode. It is based on a simple encoding
' technique, "using a keyword". Basically even if the numbers in the file
' are the same they could be two different letters because every letter
' is encoded differently.
DECLARE SUB getkeywords ()
DIM SHARED keywords(1 TO 5) AS STRING
RANDOMIZE TIMER
getkeywords
CLS
LOCATE 10, 15
COLOR 9
PRINT "Welcome to The Oracle's Encryption Program"
LOCATE 12, 25
COLOR 15
PRINT "1) Encrypt message"
LOCATE 13, 25
PRINT "2) Decrypt message"
LOCATE 14, 25
PRINT "3) Exit"
LOCATE 16, 25
INPUT "Your choice? ", choice$
IF choice$ = "1" THEN
GOTO encryption
ELSEIF choice$ = "2" THEN
GOTO decryption
ELSEIF choice$ = "3" THEN
END
ELSEIF choice$ = CHR$(27) THEN
END
ELSE
RUN
END IF
' I wouldn't normally use GOTO, but you can't redim arrays when inside
' subroutines as far as I am aware... Anyone know how???
encryption:
CLS
k = INT(RND * 5) + 1
FOR a = 1 TO LEN(keywords(k))
codes(a) = ASC(MID$(keywords(k), a, 1)) ' Store the ASCII codes in an array
NEXT a
INPUT "Type a string you want to encrypt: ", encrypt$
IF encrypt$ = CHR$(27) THEN END
INPUT "Type a name for the file the info is stored in: ", filename$
IF filename$ = CHR$(27) THEN END
IF RIGHT$(filename$, 4) <> ".txt" THEN filename$ = filename$ + ".txt"
DIM SHARED enc(1 TO LEN(encrypt$)) AS INTEGER
OPEN filename$ FOR OUTPUT AS #1
FOR b = 1 TO LEN(encrypt$) ' For each character
IF b > LEN(keywords(k)) + c THEN c = c + LEN(keywords(k)) ' If the character
' number is greater
' than the keyword
' start from the
' start of the keyword
enc(b) = ASC(MID$(encrypt$, b, 1)) + codes(b - c) ' This is simple encoding
PRINT #1, STR$(enc(b)) ' Print to file
NEXT b
CLOSE
PRINT "Your key is"; k; ". Don't lose it!!!"
WHILE INKEY$ = "": WEND
RUN
decryption:
CLS
INPUT "Enter your keycode: ", k
INPUT "Enter the filename: ", filename$
IF RIGHT$(filename$, 4) <> ".txt" THEN filename$ = filename$ + ".txt"
OPEN filename$ FOR INPUT AS #1
DO UNTIL EOF(1) ' This loop simply counts the number of lines
INPUT #1, a$
d = d + 1
LOOP
CLOSE ' How do you reposition the cursor at the beginning of a file?
' I've used CLOSE and OPEN
OPEN filename$ FOR INPUT AS #1
DIM decodes(1 TO d) AS INTEGER ' Array for storing the codes from the file
FOR o = 1 TO d ' Get the numbers in the file
INPUT #1, a%
decodes(o) = a%
NEXT o
FOR a = 1 TO LEN(keywords(k)) ' Get the codes of the keyword
codes(a) = ASC(MID$(keywords(k), a, 1))
NEXT a
DIM SHARED enc(1 TO d) AS INTEGER ' Array for the actual message
FOR l = 1 TO d
IF l > LEN(keywords(k)) + c THEN c = c + LEN(keywords(k))
enc(l) = decodes(l) - codes(l - c) ' Decode the string
PRINT CHR$(enc(l)); ' Print the result
NEXT l
WHILE INKEY$ = "": WEND
RUN
END
SUB getkeywords
keywords(1) = "roast"
keywords(2) = "qbasic"
keywords(3) = "mouse"
keywords(4) = "oracle"
keywords(5) = "algorithm"
END SUB