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

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From:  "delly20fr" <adonai@f...> Tue Oct 8, 2002  4:28 am
'Subject:  RC4 encryption for RapidQ - enjoy and be secure ;)
'
' RC4 STRONG ENCRYPTION (key until 2048 bits) for RapidQ
' designed by Del_Armg0 for rQcommunities - Enjoy this fast and secure algo.
' and if u find it usefull just give credits (rc4 is used by IE, netscape, ...)
'
' happy coding !
'
'

     $APPTYPE GUI
     $TYPECHECK ON
     $OPTIMIZE ON

     $INCLUDE "RAPIDQ.INC"

'--------- """""""""""""""""""" ---------'---------
'--------- """""""""""""""""""" ---------'---------

     DECLARE SUB Button1Click (Sender AS QBUTTON)
     DECLARE SUB Button2Click (Sender AS QBUTTON)

'--------- """""""""""""""""""" ---------'---------
'--------- """""""""""""""""""" ---------'---------

     DECLARE FUNCTION Rc4$ (s$) AS STRING
     DECLARE FUNCTION Rc4K (InitFlag) AS INTEGER
     DECLARE SUB Rc4Init (Key$)


'--------- """""""""""""""""""" ---------

     DIM se(255) AS INTEGER ' S-Box is here
     DIM ke(255) AS INTEGER

     DIM KeyLen9 AS INTEGER
     DIM KeyPtr9 AS INTEGER
     DIM StringLen9 AS INTEGER

     DIM Xq AS INTEGER
     DIM Cq AS INTEGER
     DIM Iq AS INTEGER
     DIM Jq AS INTEGER
     DIM Tq AS INTEGER

     DIM InitFLag AS INTEGER
     DIM Key$ AS STRING
     DIM Encrypted$YY AS STRING
     DIM Clear$YY AS STRING

     DIM r$ AS STRING
     DIM s$ AS STRING

     DIM mode9 AS INTEGER


'--------- """""""""""""""""""" ---------'---------
'--------- """""""""""""""""""" ---------'---------

     CREATE Form AS QFORM
      CAPTION = " RC4 Encryption for RapidQ - by Del_Armg0 - October.2002"
      Width = 435
      Height = 422
      Center
      CREATE RichEdit1 AS QRICHEDIT
       Left = 2
       Top = 5
       Width = 422
       Height = 163
       PlainText = 1
       showhint = 1
       hint = "Input text - Clear"
       AddStrings "Software coded by Del_Armg0 / Delly_ // mailto: adonai@f... // -- // ceci est un test - this is a test - the RC4/ArcFour encryption -- KEY_SIZE Max. Value = 2048 bits / 256 octets"
      END CREATE
      CREATE RichEdit2 AS QRICHEDIT
       Left = 2
       Top = 197
       Width = 422
       Height = 193
       PlainText = 1
       showhint = 1
       hint = "Output text - RC4 Encrypted"
       TabOrder = 1
      END CREATE
      CREATE Edit1 AS QEDIT
       Text = "enter_your_password_here"
       Left = 2
       Top = 170
       Width = 320
       TabOrder = 2
      END CREATE
      CREATE Button1 AS QBUTTON
       CAPTION = "ENCry"
       Left = 330
       Top = 170
       Width = 43
       TabOrder = 3
       OnClick = Button1Click
      END CREATE
      CREATE Button2 AS QBUTTON
       CAPTION = "DECry"
       Left = 377
       Top = 170
       Width = 43
       TabOrder = 3
       OnClick = Button2Click
      END CREATE
     END CREATE

     form.borderstyle = bsdialog
     Form.SHOWMODAL

'--------- """""""""""""""""""" ---------'---------
'--------- """""""""""""""""""" ---------'---------

'--------- """""""""""""""""""" ---------

     SUB Button1Click (Sender AS QBUTTON)

      mode9 = 1

      richedit2.clear

      s$ = ""
      r$ = ""
      KeyPtr9 = 0
      Xq = 0
      Cq = 0
      Iq = 0
      Jq = 0
      Tq = 0
      InitFLag = 0
      KeyLen9 = 0
      StringLen9 = 0


      Key$ = edit1.text
      Clear$YY = richedit1.text

      Rc4Init (Key$)

      Encrypted$YY = Rc4$(Clear$YY)

      DIM tt1 AS INTEGER
      DIM kar AS STRING
      DIM ascc AS INTEGER
      DIM karall AS STRING
      DIM karascc AS STRING

      karall = ""
      karascc = ""
      ascc = 0
      kar = ""
      tt1 = 0


      FOR tt1 = 1 TO LEN(Encrypted$YY)
       kar = MID$(Encrypted$YY, tt1, 1)
       ascc = ASC(kar)
       karascc = STR$(ascc)
       IF LEN(karascc) = 1 THEN
        karascc = "00"+karascc
       ELSEIF LEN(karascc) = 2 THEN
        karascc = "0"+karascc
       ELSEIF LEN(karascc) = 3 THEN
        karascc = karascc
       END IF
       karall = karall + karascc
      NEXT

      richedit2.text = "@___DEL_A_StartOfFile___|>"+CHR$(13)+CHR$(10)+ karall +CHR$(13)+CHR$(10)+"@___DEL_A_EndOfFile___|>"

     END SUB

'--------- """""""""""""""""""" ---------
'--------- """""""""""""""""""" ---------

     SUB Button2Click (Sender AS QBUTTON)

      mode9 = 2

      richedit1.clear

      s$ = ""
      r$ = ""
      KeyPtr9 = 0
      Xq = 0
      Cq = 0
      Iq = 0
      Jq = 0
      Tq = 0
      InitFLag = 0
      KeyLen9 = 0
      StringLen9 = 0


      Key$ = edit1.text
      Encrypted$YY = richedit2.text

      DIM tt2 AS INTEGER
      DIM kar2 AS STRING
      DIM ascc2 AS INTEGER
      DIM karal1 AS STRING
      DIM karal2 AS STRING

      karal1 = ""
      karal2 = ""
      ascc2 = 0
      kar2 = ""
      tt2 = 0

      DIM manip$ AS STRING
      DIM mathmo AS INTEGER

      manip$ = REPLACESUBSTR$(Encrypted$YY, "@___DEL_A_StartOfFile___|>", "")
      manip$ = REPLACESUBSTR$(manip$, "@___DEL_A_EndOfFile___|>", "")
      manip$ = REPLACESUBSTR$(manip$, CHR$(13)+CHR$(10), "")

      Encrypted$YY = manip$


      mathmo = LEN(Encrypted$YY)

      FOR tt2 = 1 TO (mathmo) STEP 3
       kar2 = MID$(Encrypted$YY, tt2, 3)
       ascc2 = VAL(kar2)
       karal1 = CHR$(ascc2)
       karal2 = karal2 + karal1

      NEXT


      Encrypted$YY = karal2

      Rc4Init (Key$)

      Clear$YY = Rc4$(Encrypted$YY)

      richedit1.text = Clear$YY

     END SUB

'--------- """""""""""""""""""" ---------
'--------- """""""""""""""""""" ---------'---------

     FUNCTION Rc4$ (s$)

      StringLen9 = LEN(s$)

      FOR xq = 1 TO StringLen9
       cq = ASC(MID$(s$, xq, 1))
       ke() = Rc4K(0) ' <---- prob here if ke without ( ) !
       r$ = r$ + CHR$(cq XOR ke()) ' <---- prob here if ke without ( ) !
      NEXT

      Rc4$ = r$

     END FUNCTION

'--------- """""""""""""""""""" ---------'---------

     SUB Rc4Init (Key$)

      KeyLen9 = LEN(Key$)

      FOR iq = 0 TO 255
       se(iq) = iq
       KeyPtr9 = KeyPtr9 + 1
       ke(iq) = ASC(MID$(Key$, KeyPtr9, 1))
       IF KeyPtr9 = KeyLen9 THEN
        KeyPtr9 = 0
       END IF
      NEXT

      FOR iq = 0 TO 255
       jq = (jq + se(iq) + ke(iq)) MOD 256
       SWAP se(iq), se(jq)
      NEXT

      iq = Rc4K(1)

     END SUB

'--------- """""""""""""""""""" ---------'---------

     FUNCTION Rc4K (InitFlag)

      STATIC iq AS INTEGER
      STATIC jq AS INTEGER

      IF InitFlag THEN
       iq = 0
       jq = 0
      ELSE
       iq = (iq + 1) MOD 256
       jq = (jq + se(iq)) MOD 256
       SWAP se(iq), se(jq)
       tq = (se(iq) + se(jq)) MOD 256
       Rc4K = se(tq)
      END IF

     END FUNCTION
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2019-7-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-10-08 19:06:28