Guidance
指路人
g.yi.org
software / rapidq / Examples / Security / encrypt / quizzer2.rqb

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $OPTION EXPLICIT            'get rapidq to check all variables
     $INCLUDE "rapidq.inc"

  'program takes encrypted files, reads them, and makes a quiz based on them

     DECLARE SUB bc

     CONST gap = 10           'gap for spacing things around forms
     CONST maxq = 50          'max number of questions per form
     CONST noc = 3            'number of choices per question

     DIM form AS QFORM                         'main form
     DIM butt AS QBUTTON                       'button to run quiz
     DIM listbox AS QLISTBOX                   'listbox to list all .cde files found
     DIM sentence(maxq) AS QLABEL              'labels for sentences
     DIM pan(maxq) AS QPANEL                   'panels to hold radio buttons
     DIM rb(maxq * noc) AS QRADIOBUTTON        'radiobutton
     DIM file AS QFILESTREAM                   'file stream for each file
     DIM fname$ AS STRING                      'file name for reading all .cde files in directory
     DIM tline$ AS STRING                      'first line of encrypted files
     DIM codeword$ AS STRING                   'codeword
     DIM codechar$ AS STRING                   'character of code word used to decrypt
     DIM cryptchar$ AS STRING                  'character from file - encrypted, needs to be decrypted
     DIM textline$ AS STRING                   'plain text line - decrypted
     DIM textchar$ AS STRING                   'plain text character
     DIM qfname$(100) AS STRING                'names of all the question files: all the .cde files
     DIM fline$(100) AS STRING                 'lines read from file
     DIM pline$(100) AS STRING                 'plain line
     DIM temp$ AS STRING                       'temp string
     DIM choice$(noc) AS STRING                'choices from decrypted file
     DIM qcount AS INTEGER                     'question count from the file
     DIM lc AS INTEGER                         'line count - how many lines read from encrypted file
     DIM cwl AS INTEGER                        'code word letter to use for decryption
     DIM b AS INTEGER                          'counter
     DIM i AS INTEGER                          'counter
     DIM a AS INTEGER                          'counter
     DIM os AS INTEGER                         'offset - used to put things on form
     form.width = 800
     form.height = 500
     qcount = 0
     codeword$ = "tigerlily"
     listbox.PARENT = form
     butt.PARENT = form
     butt.top = 100
     butt.onclick = bc
     butt.CAPTION = "do quiz"
     fname$ = DIR$("*.cde", 0)                 'start looking for .cde files in current directory
     WHILE fname$ <> ""
      qcount = qcount + 1
      qfname$(qcount) = fname$
      file.OPEN(fname$, fmopenread)
      tline$ = file.readline                  'read the first lines and put into an array
      file.CLOSE
      listbox.additems tline$
      fname$ = DIR$                           'see if there is another file to add
     WEND
     form.center
     form.SHOWMODAL

     SUB bc
      file.OPEN(qfname$(listbox.itemindex + 1), fmopenread)  'open the file given by
                                                           'itemindex - note itemindex starts at 0, so have to add 1
      lc = 0                                                 'lines read = 0
      FOR a = 1 TO 50                                        'hide everything
       sentence(a).visible = false
       pan(a).visible = false
      NEXT a
      WHILE NOT file.eof                                     'read every line
       lc = lc + 1
       fline$(lc) = file.readline
       textline$ = ""
       IF lc = 1 THEN
        textline$ = fline$(lc)                             'first line not encrypted
       ELSE
        FOR b = 1 TO LEN(fline$(lc))                       'decrypt every character in line
         cwl = b MOD LEN(codeword$)                       'use first character, then next, etc cyclically
         IF cwl = 0 THEN
          cwl = LEN(codeword$)
         END IF
         codechar$ = MID$(codeword$, cwl, 1)
         cryptchar$ = MID$(fline$(lc), b, 1)
         textchar$ = CHR$(40 + (ASC(cryptchar$) - 40) - (ASC(codechar$) - 40))
                                                           'bi decryption line
         textline$ = textline$ + textchar$
        NEXT b
        textline$ = reverse$(textline$)
        textline$ = LEFT$(textline$, INSTR(textline$, "#")-1)
        pline$(lc) = textline$                             'decryption complete!
       END IF
'      showmessage textline$
      WEND
      FOR i = 2 TO lc   'for each line read - all this bit should be familiar
       sentence(i).width = 300
       sentence(i).height = 40
       sentence(i).top = gap + (i-1)*(sentence(i).height + gap)
       sentence(i).left = 150
       sentence(i).PARENT = form
       sentence(i).CAPTION = LEFT$(pline$(i), INSTR(pline$(i), ":")-1)
        'get the left part of each line up till the first :
       sentence(i).visible = true
       temp$ = RIGHT$(pline$(i), LEN(pline$(i))-INSTR(pline$(i), ":"))
        'the bit on the right of each line
       choice$(1)=LEFT$(temp$, INSTR(temp$, ":")-1)
        'get the bit up to the first : - this is first choice
       temp$ = RIGHT$(temp$, LEN(temp$)-INSTR(temp$, ":"))
        'the bit left over
       choice$(2)=LEFT$(temp$, INSTR(temp$, ":")-1)
       choice$(3)=RIGHT$(temp$, LEN(temp$)-INSTR(temp$, ":"))
       pan(i).height = 30
       pan(i).width = 350
       pan(i).top = sentence(i).top
       pan(i).left = 400
       pan(i).bevelwidth = 0  'not raised panel
       pan(i).visible = true
       pan(i).PARENT = form
       FOR a = 1 TO 3 'set radio buttons in groups of three
        rb((i-1)*3+a).PARENT = pan(i)
        rb((i-1)*3+a).width = 100
        rb((i-1)*3+a).height = pan(i).height - 2
        rb((i-1)*3+a).top = 1
        rb((i-1)*3+a).left = 10+(a-1)*rb(1).width
        rb((i-1)*3+a).tag = 0
        rb((i-1)*3+a).visible = true
       NEXT a
       os = (i-1)*3  'offset for setting up the radio buttons
       SELECT CASE INT(RND*6) 'six ways of randomly arranging 3 choices:
       CASE 0 '123
        rb(os + 1).CAPTION = choice$(1)
        rb(os + 2).CAPTION = choice$(2)
        rb(os + 3).CAPTION = choice$(3)
        rb(os + 1).tag = 100            'whichever radiobutton has tag 100 is the right answer
       CASE 1 '132
        rb(os + 1).CAPTION = choice$(1)
        rb(os + 2).CAPTION = choice$(3)
        rb(os + 3).CAPTION = choice$(2)
        rb(os + 1).tag = 100
       CASE 2 '213
        rb(os + 1).CAPTION = choice$(2)
        rb(os + 2).CAPTION = choice$(1)
        rb(os + 3).CAPTION = choice$(3)
        rb(os + 2).tag = 100
       CASE 3 '231
        rb(os + 1).CAPTION = choice$(2)
        rb(os + 2).CAPTION = choice$(3)
        rb(os + 3).CAPTION = choice$(1)
        rb(os + 3).tag = 100
       CASE 4 '312
        rb(os + 1).CAPTION = choice$(3)
        rb(os + 2).CAPTION = choice$(1)
        rb(os + 3).CAPTION = choice$(2)
        rb(os + 2).tag = 100
       CASE 5 '321
        rb(os + 1).CAPTION = choice$(3)
        rb(os + 2).CAPTION = choice$(2)
        rb(os + 3).CAPTION = choice$(1)
        rb(os + 3).tag = 100
       END SELECT
      NEXT i
     END SUB
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-2-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2004-11-25 00:00:00