Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Challenges
#26
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... Sad )

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

Big Grin
Reply


Messages In This Thread
New Challenges - by wildcard - 09-10-2002, 03:46 AM
New Challenges - by wizardlife - 09-10-2002, 06:41 AM
New Challenges - by wizardlife - 09-10-2002, 06:44 AM
Another challenge - by LooseCaboose - 09-10-2002, 09:11 AM
New Challenges - by aetherfox - 09-15-2002, 06:21 PM
New Challenges - by wizardlife - 09-16-2002, 01:28 AM
New Challenges - by wildcard - 09-16-2002, 02:14 AM
New Challenges - by mofu - 09-26-2002, 01:10 AM
New Challenges - by wildcard - 09-26-2002, 02:38 AM
New Challenges - by Neo - 09-26-2002, 02:29 PM
New Challenges - by mofu - 09-26-2002, 05:02 PM
New Challenges - by wildcard - 09-26-2002, 07:36 PM
New Challenges - by mofu - 09-27-2002, 12:32 AM
New Challenges - by na_th_an - 11-06-2002, 03:30 AM
New Challenges - by wizardlife - 11-06-2002, 04:30 AM
loosecabooses challange... - by eKrax - 12-17-2002, 04:44 AM
New Challenges - by LooseCaboose - 12-17-2002, 04:59 AM
New Challenges - by LooseCaboose - 12-18-2002, 06:59 AM
... - by eKrax - 12-18-2002, 08:06 AM
New Challenges - by LooseCaboose - 12-18-2002, 09:22 AM
New Challenges - by Generic - 02-03-2003, 04:30 AM
About the pi program... - by oracle - 03-21-2003, 09:39 AM
New Challenges - by someone42 - 03-21-2003, 03:30 PM
pi - by oracle - 03-22-2003, 03:25 AM
New Challenges - by someone42 - 03-22-2003, 08:43 AM
New Challenges - by oracle - 03-22-2003, 11:45 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)