Guidance
指路人
g.yi.org
software / rapidq / Examples / String & Text / Encryption / secure memo.bas

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

  
'Coded by S.Boukas'
'A secure memo pad with RC4 encryption'
'Before open an encrypted file,or save a file you want to be encrypted'
'set the password,otherwise will be opened or saved as it is'
'You will think that it's only an example,but soon you'll use it'
     $INCLUDE "rapidq.inc"
     DECLARE SUB dclose
     DIM pw$ AS STRING
     DIM s(0 TO 255)
     DIM k(0 TO 255)
     DIM filename AS STRING
     DIM file1 AS QFILESTREAM
     DIM n$ AS STRING
     DIM d$ AS STRING
     DIM i AS INTEGER
     DIM x AS INTEGER
     DIM y AS INTEGER
     DIM j AS INTEGER
     DIM b AS BYTE

     DIM mainform AS QFORM
     mainform.CAPTION = "Secure memo v1.0..."
     mainform.Width = 600
     mainform.Height = 400
     mainform.Center
     DIM richedit AS QRICHEDIT
     richedit.PARENT=mainform
     richedit.width=mainform.clientwidth
     richedit.height=mainform.clientheight
     richedit.scrollbars=2
     richedit.plaintext=true
     wordwrap=true
     DIM mainmenu AS QMAINMENU
     mainmenu.PARENT=mainform
     DIM file AS QMENUITEM
     DIM about AS QMENUITEM
     DIM list AS QMENUITEM
     list.CAPTION="&By S.Boukas (c)2004"
     mainmenu.additems file,about
     file.CAPTION="&File"
     about.CAPTION="&About"
     DIM new AS QMENUITEM
     new.CAPTION="&New"
     DIM OPEN AS QMENUITEM
     OPEN.CAPTION="&Open"
     DIM saveas AS QMENUITEM
     saveas.CAPTION="&Save as.."
     DIM password AS QMENUITEM
     password.CAPTION="&Password"
     DIM exits AS  QMENUITEM
     exits.CAPTION="&Exit"
     file.additems new,OPEN,saveas,password,exits
     about.additems list
     DIM dialogbox AS QFORM
     DIM editbox AS QEDIT
     DIM button AS QBUTTON
     dialogbox.borderstyle=bsdialog
     dialogbox.CAPTION="Password.."
     dialogbox.width=300
     dialogbox.height=80
     dialogbox.center
     editbox.PARENT=dialogbox
     editbox.top=15
     editbox.left=20
     editbox.width=170
     editbox.text=""
     button.PARENT=dialogbox
     button.CAPTION="&OK"
     button.top=13
     button.left=210
     button.width=70
     button.onclick=dclose


     DIM FxFont AS QFONT
     FxFont.Name = "courier new"
     FxFont.size=9
     FxFont.COLOR=0
     richedit.font=fxfont




     SUB newclick
      richedit.clear
      mainform.CAPTION="Secure memo v1.0"+" Untitled"
      editbox.text=""
     END SUB

     SUB passwordclick
      dialogbox.SHOWMODAL
     END SUB

     SUB openclick
      d$=""
      PW$=editbox.text
      DIM opendialog AS QOPENDIALOG
      IF opendialog.EXECUTE THEN
       filename=opendialog.filename
       mainform.CAPTION="Secure memo v1.0"+" "+filename
       IF pw$="" THEN richedit.loadfromfile filename:GOTO dd
       i=0
       j=0
       FOR i=0 TO 255
        s(i)=i
       NEXT i
       j=1
       FOR i=0 TO 255
        IF j>LEN(pw$) THEN j=1
        k(i)=ASC(MID$(pw$,j,1))
        j=j+1
       NEXT i
       j=0
       FOR i=0 TO 255
        j=(j+s(i)+k(i))MOD 256
        SWAP s(i),s(j)
       NEXT i
       file1.OPEN(filename,fmopenread)
 cc:
       IF file1.eof=-1 THEN file1.CLOSE:GOTO aa
       file1.READ(b)
       i=(i+1)MOD 256
       j=(j+s(i))MOD 256
       SWAP s(i),s(j)
       t=(s(i)+(s(j)MOD 256))MOD 256
       y=s(t)
       d$=d$+CHR$(b XOR y):GOTO cc
 aa:
       richedit.text=d$
       editbox.text=""
 dd:
      END IF
     END SUB

     SUB saveasclick
      d$=""
      pw$=editbox.text
      DIM savedialog AS QSAVEDIALOG
      IF savedialog.EXECUTE THEN
       filename=savedialog.filename
       mainform.CAPTION="Secure memo v1.0"+" "+filename
       IF richedit.text="" THEN SHOWMESSAGE ("nothing to save !"):EXIT SUB
       IF pw$="" THEN richedit.savetofile filename:GOTO ee
       n$=richedit.text
       i=0
       j=0
       FOR i=0 TO 255
        s(i)=i
       NEXT i
       j=1
       FOR i=0 TO 255
        IF j>LEN(pw$) THEN j=1
        k(i)=ASC(MID$(pw$,j,1))
        j=j+1
       NEXT i
       j=0
       FOR i=0 TO 255
        j=(j+s(i)+k(i))MOD 256
        SWAP s(i),s(j)
       NEXT i
       FOR x=1 TO LEN(n$)
        a=ASC(MID$(n$,x,1))
        i=(i+1)MOD 256
        j=(j+s(i))MOD 256
        SWAP s(i),s(j)
        t=(s(i)+(s(j)MOD 256))MOD 256
        y=s(t)
        d$=d$+CHR$(a XOR y)
       NEXT x
       file1.OPEN(filename,fmcreate)
       file1.write(d$)
       file1.CLOSE
       SHOWMESSAGE ("text encrypted and saved !")
       editbox.text=""
 ee:
      END IF
     END SUB

     SUB dclose
      dialogbox.CLOSE
     END SUB

     SUB exitsclick
      mainform.CLOSE

     END SUB

     SUB aboutclick
      SHOWMESSAGE ("S.Boukas (c)2004")
     END SUB


     SUB formresize
      richedit.width=mainform.clientwidth
      richedit.height=mainform.clientheight
     END SUB
'subroutines always at the end'
     new.onclick=newclick
     OPEN.onclick=openclick
     saveas.onclick=saveasclick
     exits.onclick=exitsclick
     password.onclick=passwordclick

     mainform.onresize=formresize
     MAINFORM.SHOWMODAL


掌柜推荐
 
 
¥738.00 ·
 
 
¥1,480.00 ·
 
 
¥397.00 ·
 
 
¥950.00 ·
 
 
¥264.00 ·
 
 
¥1,005.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2004-02-17 02:23:26