4guys RC4 encryption demo

Discussion in 'ASP General' started by Wilk Teverbaugh, Jan 13, 2004.

  1. I am using 4guys RC4 demo and am a little lost on how to store my encrypted
    strings. In the demo it shows how to encrypt a string into binary and then
    use URLencode to encode it. I'm not sure how to decode the string into
    binary so I can then unencrypt my string... I am storing my strings in SQL
    server.

    Is it possible to just store my strings as binary or do I need to encode
    them first? If I need to encode them how can I decode them so I can then
    decrypt them?

    Any help would be greatly appreciated as I am a little lost.



    Dim sbox(255)
    Dim key(255)
    Sub RC4Initialize(strPwd)
    dim tempSwap
    dim a
    dim b
    intLength = len(strPwd)
    For a = 0 To 255
    key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
    sbox(a) = a
    next
    b = 0
    For a = 0 To 255
    b = (b + sbox(a) + key(a)) Mod 256
    tempSwap = sbox(a)
    sbox(a) = sbox(b)
    sbox(b) = tempSwap
    Next
    End Sub
    Function EnDeCrypt(plaintxt, psw)
    dim temp
    dim a
    dim i
    dim j
    dim k
    dim cipherby
    dim cipher
    i = 0
    j = 0
    RC4Initialize psw
    For a = 1 To Len(plaintxt)
    i = (i + 1) Mod 256
    j = (j + sbox(i)) Mod 256
    temp = sbox(i)
    sbox(i) = sbox(j)
    sbox(j) = temp
    k = sbox((sbox(i) + sbox(j)) Mod 256)
    cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
    cipher = cipher & Chr(cipherby)
    Next
    EnDeCrypt = cipher
    End Function
    dim etime, stime
    dim psw, txt
    dim strTemp
    dim x
    etime = 0
    stime = 0

    psw = "passphrase"
    cString = "test string.."
    stime = timer
    strTemp = EnDeCrypt(cString, psw)
    etime = cdbl(timer - stime)

    function decode(myStr)
    dim k,s1,s2
    while inStr(myStr,"&#")
    k = inStr(myStr,"&#")
    s1= Mid(myStr,k,6)
    s2= Mid(s1,3,3)
    myStr = replace(myStr,s1,chr(s2))
    wend
    decode=myStr
    end function


    for x = 1 to len(strTemp)
    newString = newString & right(string(2,"0") & hex(asc(mid(strTemp, x,
    1))),2)
    next


    test1 = EnDeCrypt(cString, psw)
    response.write "Binary string = " & test1 & "<br>"
    encodedStr = server.urlencode(test1)
    response.write "URL encoded string = " & encodedStr & "<br>"
    response.write "Decrypted String = " & EnDeCrypt(test1, psw)
     
    Wilk Teverbaugh, Jan 13, 2004
    #1
    1. Advertising

  2. Wilk Teverbaugh

    swp Guest

    "Wilk Teverbaugh" <> wrote in message news:<#>...
    > I am using 4guys RC4 demo and am a little lost on how to store my encrypted
    > strings. In the demo it shows how to encrypt a string into binary and then
    > use URLencode to encode it. I'm not sure how to decode the string into
    > binary so I can then unencrypt my string... I am storing my strings in SQL
    > server.
    >
    > Is it possible to just store my strings as binary or do I need to encode
    > them first? If I need to encode them how can I decode them so I can then
    > decrypt them?
    >
    > Any help would be greatly appreciated as I am a little lost.
    >
    >
    >
    > Dim sbox(255)
    > Dim key(255)
    > Sub RC4Initialize(strPwd)
    > dim tempSwap
    > dim a
    > dim b
    > intLength = len(strPwd)
    > For a = 0 To 255
    > key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
    > sbox(a) = a
    > next
    > b = 0
    > For a = 0 To 255
    > b = (b + sbox(a) + key(a)) Mod 256
    > tempSwap = sbox(a)
    > sbox(a) = sbox(b)
    > sbox(b) = tempSwap
    > Next
    > End Sub
    > Function EnDeCrypt(plaintxt, psw)
    > dim temp
    > dim a
    > dim i
    > dim j
    > dim k
    > dim cipherby
    > dim cipher
    > i = 0
    > j = 0
    > RC4Initialize psw
    > For a = 1 To Len(plaintxt)
    > i = (i + 1) Mod 256
    > j = (j + sbox(i)) Mod 256
    > temp = sbox(i)
    > sbox(i) = sbox(j)
    > sbox(j) = temp
    > k = sbox((sbox(i) + sbox(j)) Mod 256)
    > cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
    > cipher = cipher & Chr(cipherby)
    > Next
    > EnDeCrypt = cipher
    > End Function
    > dim etime, stime
    > dim psw, txt
    > dim strTemp
    > dim x
    > etime = 0
    > stime = 0
    >
    > psw = "passphrase"
    > cString = "test string.."
    > stime = timer
    > strTemp = EnDeCrypt(cString, psw)
    > etime = cdbl(timer - stime)
    >
    > function decode(myStr)
    > dim k,s1,s2
    > while inStr(myStr,"&#")
    > k = inStr(myStr,"&#")
    > s1= Mid(myStr,k,6)
    > s2= Mid(s1,3,3)
    > myStr = replace(myStr,s1,chr(s2))
    > wend
    > decode=myStr
    > end function
    >
    >
    > for x = 1 to len(strTemp)
    > newString = newString & right(string(2,"0") & hex(asc(mid(strTemp, x,
    > 1))),2)
    > next
    >
    >
    > test1 = EnDeCrypt(cString, psw)
    > response.write "Binary string = " & test1 & "<br>"
    > encodedStr = server.urlencode(test1)
    > response.write "URL encoded string = " & encodedStr & "<br>"
    > response.write "Decrypted String = " & EnDeCrypt(test1, psw)


    I use this function to decode URLs that were URLencoded:

    function URLDecode(e)
    Dim r, s, t
    Dim p
    s = replace(e, "+", " ")
    for p = 1 to len(s)
    t = mid(s, p, 1)
    if ((t = "%") and (mid(s, p+1, 1) < "A")) then
    if p + 2 < len(s) then
    r = r & chr(cint("&H" & mid(s, p + 1, 2)))
    p = p + 2
    end if
    else
    r = r & t
    end if
    next
    URLDecode = r
    end function

    hope it helps

    swp
     
    swp, Jan 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boogie El Aceitoso

    RC4 Implementation

    Boogie El Aceitoso, Sep 1, 2003, in forum: C++
    Replies:
    3
    Views:
    4,980
    Jerry Coffin
    Sep 3, 2003
  2. SenthilVel

    Using NAnt RC4 to build .Net 1.1 Code

    SenthilVel, Jun 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    554
    SenthilVel
    Jun 12, 2006
  3. Edward K. Ream

    ANN: Leo 4.1 rc4: An outlining editor

    Edward K. Ream, Feb 4, 2004, in forum: Python
    Replies:
    0
    Views:
    295
    Edward K. Ream
    Feb 4, 2004
  4. F. GEIGER
    Replies:
    9
    Views:
    1,254
    F. GEIGER
    May 3, 2004
  5. Andy Leszczynski

    wxPython demo /Process does not open new demo

    Andy Leszczynski, Feb 18, 2005, in forum: Python
    Replies:
    1
    Views:
    665
    Andy Leszczynski
    Feb 18, 2005
Loading...

Share This Page