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

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

  
'
' RC4 Example - File Crypter
' (C) 2003-09-28 Martin Wehner
'
' Contact:  mailto:martin.wehner@firemail.de
' Homepage: http://mitglied.lycos.de/maweso/
'
' Compile this source code with the RapidQ Compiler
' (available at http://www.basicguru.com/rapidq).
' For better runtime stability it is highly recommended
' to use the patched Rapid-Q Library Files available at
' http://www.angelfire.com/space/netcensus/ when
' compiling this source.
'
' This source code is distributed under GNU General
' Public License.
'

     $INCLUDE "RapidQ.inc"
     $INCLUDE "RC4crypt.inc"

     CONST PACKET_SIZE = 1024
     CONST KEY_LIMIT = 5   ' Limited to 5 characters due to U.S. export restrictions
     CONST CR = CHR$(13)

     DIM hint AS STRING
     hint = "Encode: Type in the key. Select ''RC4crypt.inc'' as source "
     hint = hint + "file and ''encode.txt'' as target file. Then press "
     hint = hint + "''Encode / Decode''. If you open ''encode.txt'' with "
     hint = hint + "a text editor then you will see that its content is "
     hint = hint + "encrypted." + CR + CR
     hint = hint + "Decode: Type in the same key. Select ''encode.txt'' as "
     hint = hint + "source file and ''decode.txt'' as target file. Then "
     hint = hint + "press ''Encode / Decode''. If you open ''decode.txt'' "
     hint = hint + "with a text editor then you will see that its content "
     hint = hint + "is equal to the content of ''RC4crypt.inc''." + CR + CR
     hint = hint + "DISCLAIMER: ABSOLUTELY NO WARRANTY IS GIVEN FOR THIS "
     hint = hint + "PROGRAM AND THE RC4 COMPONENT! USE THIS PROGRAM AT "
     hint = hint + "YOUR OWN RISK!"

     DECLARE SUB FormClose
     DECLARE SUB SelectSource
     DECLARE SUB SelectTarget
     DECLARE SUB FileCrypt
     DECLARE SUB WndProc

     CREATE Form AS QFORM
      CAPTION = "RC4 Example - File Crypter"
      Width = 500
      Height = 380
      Center
      BorderStyle = bsSingle
      DelBorderIcons biMaximize
      WndProc = WndProc
      CREATE LabelHint AS QLABEL
       CAPTION = hint
       Left = 20
       Top = 20
       Width = 450
       Height = 109
       Wordwrap = 1
      END CREATE
      CREATE LabelKey AS QLABEL
       CAPTION = "Key:"
       Left = 25
       Top = 190
       Width = 80
      END CREATE
      CREATE EditKey AS QEDIT
       Text = ""
       Left = 110
       Top = 190
       Width = 60
      END CREATE
      CREATE LabelLimit AS QLABEL
       CAPTION = "(max. 5 characters due to U.S. export restrictions)"
       Left = 185
       Top = 190
       Width = 285
      END CREATE
      CREATE LabelSource AS QLABEL
       CAPTION = "Source File:"
       Left = 25
       Top = 220
       Width = 80
      END CREATE
      CREATE EditSource AS QEDIT
       Text = ""
       Left = 110
       Top = 220
       Width = 240
      END CREATE
      CREATE ButtonSource AS QBUTTON
       CAPTION = "Select..."
       Left = 370
       Top = 220
       Width = 95
       OnClick = SelectSource
      END CREATE
      CREATE LabelTarget AS QLABEL
       CAPTION = "Target File:"
       Left = 25
       Top = 250
       Width = 80
      END CREATE
      CREATE EditTarget AS QEDIT
       Text = ""
       Left = 110
       Top = 250
       Width = 240
      END CREATE
      CREATE ButtonTarget AS QBUTTON
       CAPTION = "Select..."
       Left = 370
       Top = 250
       Width = 95
       OnClick = SelectTarget
      END CREATE
      CREATE ButtonRC4 AS QBUTTON
       CAPTION = "Encode / Decode"
       Left = 110
       Top = 295
       Width = 240
       OnClick = FileCrypt
      END CREATE
      CREATE ButtonExit AS QBUTTON
       CAPTION = "Exit"
       Left = 370
       Top = 295
       Width = 95
       OnClick = FormClose
      END CREATE
      CREATE Gauge AS QGAUGE
       Left = 25
       Top = 290
       Height = 30
       Width = 60
       Position = 0
       Visible = False
       Kind = gkNeedle
       BorderStyle = bsNone
       BackColor = Form.COLOR
      END CREATE
     END CREATE

     SUB WndProc (hWnd AS LONG, uMsg AS LONG, wParam AS LONG, lParam AS LONG)
     END SUB

     SUB FormClose
      Form.CLOSE
     END SUB

     SUB SelectSource
      DIM OpenDialog AS QOPENDIALOG

      OpenDialog.InitialDir = CURDIR$
      IF OpenDialog.EXECUTE THEN EditSource.Text = OpenDialog.FileName
     END SUB

     SUB SelectTarget
      DIM SaveDialog AS QSAVEDIALOG

      SaveDialog.InitialDir = CURDIR$
      IF SaveDialog.EXECUTE THEN EditTarget.Text = SaveDialog.FileName
     END SUB

     SUB FileCrypt
      DIM source AS QFILESTREAM
      DIM target AS QFILESTREAM
      DIM i AS LONG, l AS LONG, n AS LONG
      DIM packet AS STRING
      DIM rc4 AS QRC4

      IF EditKey.Text <> "" AND EditSource.Text <> "" AND EditTarget.Text <> "" THEN
       IF FILEEXISTS(EditSource.Text) THEN
        rc4.Init(LEFT$(EditKey.Text, KEY_LIMIT))
        source.OPEN(EditSource.Text, fmOpenRead)
        target.OPEN(EditTarget.Text, fmCreate)

        Gauge.Position = 0
        Gauge.Visible = True
        l = source.Size

        i = l
        WHILE 0 < i
         n = IIF(PACKET_SIZE < i, PACKET_SIZE, i)
         packet = source.ReadBinStr(n)
         target.WriteBinStr(rc4.Pipe(packet), n)

         Gauge.Position = ((l - i) * 100) \ l
         i = i - PACKET_SIZE
        WEND
        Gauge.Visible = False

        target.CLOSE
        source.CLOSE
       ELSE
        SHOWMESSAGE("Cannot open Source File!")
       END IF
      ELSE
       SHOWMESSAGE("You must fill out the input fields!")
      END IF
     END SUB

     Form.SHOWMODAL
掌柜推荐
 
 
¥1,420.00 ·
 
 
¥950.00 ·
 
 
¥288.00 ·
 
 
¥738.00 ·
 
 
¥397.00 ·
 
 
¥750.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:57:24