 # Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Sun Jan 26, 2020 6:10 am All times are UTC - 5 hours  Page 1 of 2 [ 16 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: RC4 Encryption Posted: Sun Feb 03, 2008 2:20 pm Joined: Sun Feb 03, 2008 2:17 pm
Posts: 1
Has anyone got the code for RC4 encryption in realbasic

This is the closest I could find but I can't convert it `Public Function RC4(ByVal Expression As String, ByVal Password As String) As String  On Error Resume Next  Dim RB(0 To 255) As Integer, X As Long, Y As Long, Z As Long, Key() As Byte, ByteArray() As Byte, Temp As Byte  If Len(Password) = 0 Then    Exit Function  End If  If Len(Expression) = 0 Then    Exit Function  End If  If Len(Password) > 256 Then    Key() = StrConv(Left\$(Password, 256), vbFromUnicode)  Else    Key() = StrConv(Password, vbFromUnicode)  End If  For X = 0 To 255    RB(X) = X  Next X  X = 0  Y = 0  Z = 0  For X = 0 To 255    Y = (Y + RB(X) + Key(X Mod Len(Password))) Mod 256    Temp = RB(X)    RB(X) = RB(Y)    RB(Y) = Temp  Next X  X = 0  Y = 0  Z = 0  ByteArray() = StrConv(Expression, vbFromUnicode)  For X = 0 To Len(Expression)    Y = (Y + 1) Mod 256    Z = (Z + RB(Y)) Mod 256    Temp = RB(Y)    RB(Y) = RB(Z)    RB(Z) = Temp    ByteArray(X) = ByteArray(X) Xor (RB((RB(Y) + RB(Z)) Mod 256))  Next X  RC4 = StrConv(ByteArray, vbUnicode)End Function`

It's visual basic

Top Post subject: Re: RC4 Encryption Posted: Thu May 29, 2008 3:58 pm  Joined: Sun Dec 10, 2006 7:57 am
Posts: 124
Sorry about the delayed reply; however, here's the source to a method I converted ALONG time ago! Works like a champ! Enjoy! `function rc4(strData as string, strKey as string) as string    dim memAsciiArray(255) as integer  dim memKeyArray(255)   as integer  dim memJump            as integer  dim memTemp            as integer  dim memY               as integer  dim intKeyLength       as integer  dim intIndex           as integer  dim intT               as integer  dim intX               as integer  dim strCData           as string    intKeyLength = len(strKey)    for intIndex = 0 to 255    memKeyArray(intIndex)   = asc(mid(strKey, ((intIndex) mod (intKeyLength)) + 1, 1))  next    for intIndex = 0 to 255    memAsciiArray(intIndex) = intIndex  next    for intIndex = 0 to 255    memJump                 = (memJump + memAsciiArray(intIndex) + memKeyArray(intIndex)) mod 256    memTemp                 = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump)  = memTemp  next    intIndex = 0  memJump  = 0    for intX = 1 to len(strData)    intIndex                = (intIndex + 1) mod 256    memJump                 = (memJump + memAsciiArray(intIndex)) mod 256    intT                    = (memAsciiArray(intIndex) + memAsciiArray(memJump)) mod 256    memTemp                 = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump)  = memTemp    memY                    = memAsciiArray(intT)    strCData                = strCData + chr(bitwise.bitxor(asc(mid(strData, intX, 1)), bitwise.bitxor(memTemp,memY)))  next    return strCData  end function`

_________________
Respectfully,
Eric Brown

Top Post subject: Re: RC4 Encryption Posted: Thu Feb 26, 2009 6:28 pm Joined: Sun Feb 22, 2009 8:08 pm
Posts: 11
Per suggestions on another post:

viewtopic.php?f=1&t=26586&p=141899#p141899

I've modified this code to use memoryblocks, which greatly speeds up the code (i.e., from over 4 minutes to less than 3 seconds for 120,000 characters). Of course this time will vary according to your computer.

`Dim MM as MemoryBlock = strDataDim MM2 as New MemoryBlock(LenB(strData))intKeyLength = len(strKey)for intIndex = 0 to 255  memKeyArray(intIndex) = asc(mid(strKey, ((intIndex) mod (intKeyLength)) + 1, 1))nextfor intIndex = 0 to 255  memAsciiArray(intIndex) = intIndexnextfor intIndex = 0 to 255  memJump = (memJump + memAsciiArray(intIndex) + memKeyArray(intIndex)) mod 256  memTemp = memAsciiArray(intIndex)  memAsciiArray(intIndex) = memAsciiArray(memJump)  memAsciiArray(memJump) = memTempnextintIndex = 0memJump = 0for intX = 1 to theLen  intIndex = (intIndex + 1) mod 256  memJump = (memJump + memAsciiArray(intIndex)) mod 256  intT = (memAsciiArray(intIndex) + memAsciiArray(memJump)) mod 256  memTemp = memAsciiArray(intIndex)  memAsciiArray(intIndex) = memAsciiArray(memJump)  memAsciiArray(memJump) = memTemp  memY = memAsciiArray(intT)  mm2.Byte(intX - 1) = bitwise.bitxor(val("&h" + hex(MM.byte(IntX - 1))), bitwise.bitxor(memTemp,memY))nextreturn MM2`

Top Post subject: Re: RC4 Encryption Posted: Wed Dec 22, 2010 9:48 pm  Joined: Sun Aug 22, 2010 10:27 pm
Posts: 108
edb wrote:
Sorry about the delayed reply; however, here's the source to a method I converted ALONG time ago! Works like a champ! Enjoy! `function rc4(strData as string, strKey as string) as string    dim memAsciiArray(255) as integer  dim memKeyArray(255)   as integer  dim memJump            as integer  dim memTemp            as integer  dim memY               as integer  dim intKeyLength       as integer  dim intIndex           as integer  dim intT               as integer  dim intX               as integer  dim strCData           as string    intKeyLength = len(strKey)    for intIndex = 0 to 255    memKeyArray(intIndex)   = asc(mid(strKey, ((intIndex) mod (intKeyLength)) + 1, 1))  next    for intIndex = 0 to 255    memAsciiArray(intIndex) = intIndex  next    for intIndex = 0 to 255    memJump                 = (memJump + memAsciiArray(intIndex) + memKeyArray(intIndex)) mod 256    memTemp                 = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump)  = memTemp  next    intIndex = 0  memJump  = 0    for intX = 1 to len(strData)    intIndex                = (intIndex + 1) mod 256    memJump                 = (memJump + memAsciiArray(intIndex)) mod 256    intT                    = (memAsciiArray(intIndex) + memAsciiArray(memJump)) mod 256    memTemp                 = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump)  = memTemp    memY                    = memAsciiArray(intT)    strCData                = strCData + chr(bitwise.bitxor(asc(mid(strData, intX, 1)), bitwise.bitxor(memTemp,memY)))  next    return strCData  end function`

Thank you, but where is the corresponding decrypt function?

_________________
Zero-Null-Bit Software.
Code Generator for RealBasic: http://rb.znb.cc

Top Post subject: Re: RC4 Encryption Posted: Thu Dec 23, 2010 4:03 am  Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
RC4 is symmetric. That means you use the same function to decrypt as to encrypt.

Here's that RC4 function again, only this time it'll compile `Function rc4(strData as string, strKey as String) As String  Dim MM as MemoryBlock = strData  Dim MM2 as New MemoryBlock(LenB(strData))  dim memAsciiArray(255) as integer  dim memKeyArray(255)   as integer  dim memJump as integer  dim memTemp as integer  dim memY as integer  dim intKeyLength as integer  dim intIndex as integer  dim intT as integer  dim intX as integer    intKeyLength = len(strKey)    for intIndex = 0 to 255    memKeyArray(intIndex) = asc(mid(strKey, ((intIndex) mod (intKeyLength)) + 1, 1))  next    for intIndex = 0 to 255    memAsciiArray(intIndex) = intIndex  next    for intIndex = 0 to 255    memJump = (memJump + memAsciiArray(intIndex) + memKeyArray(intIndex)) mod 256    memTemp = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump) = memTemp  next    intIndex = 0  memJump = 0    for intX = 1 to MM2.Size    intIndex = (intIndex + 1) mod 256    memJump = (memJump + memAsciiArray(intIndex)) mod 256    intT = (memAsciiArray(intIndex) + memAsciiArray(memJump)) mod 256    memTemp = memAsciiArray(intIndex)    memAsciiArray(intIndex) = memAsciiArray(memJump)    memAsciiArray(memJump) = memTemp    memY = memAsciiArray(intT)    mm2.Byte(intX - 1) = bitwise.bitxor(val("&h" + hex(MM.byte(IntX - 1))), bitwise.bitxor(memTemp,memY))  next    return MM2End Function`

_________________
Boredom Software

Top Post subject: Re: RC4 Encryption Posted: Thu Dec 23, 2010 4:25 am  Joined: Sun Aug 22, 2010 10:27 pm
Posts: 108
Oh, i got it.

Thank you . _________________
Zero-Null-Bit Software.
Code Generator for RealBasic: http://rb.znb.cc

Top Post subject: Re: RC4 Encryption Posted: Tue Jun 14, 2011 12:23 am Joined: Thu Dec 02, 2010 10:17 pm
Posts: 75
Hi,
I actually have been doing some tests on this and im wondering why does it take so long to encrypt larger streams?

Top Post subject: Re: RC4 Encryption Posted: Tue Jun 14, 2011 12:29 pm  Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Because they're large?

How large are we talking about here?

_________________
Boredom Software

Top Post subject: Re: RC4 Encryption Posted: Fri May 04, 2012 11:55 am Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
Being new to Real Studio I have to ask how to Decrypt using RC4

I got it to Encrypt/Encode but can't seem to figure out how to Decrypt/Decode
a string.

Can anyone help with this ?

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac

Top Post subject: Re: RC4 Encryption Posted: Fri May 04, 2012 12:15 pm  Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
RC4 is symmetric. That is to say you do precisely the same thing to decrypt as you did to encrypt.

If M is a plaintext message, C is the enciphered version of M, and RC4 is the cipher function, then:

RC4(M) = C
and
RC4(C) = M

_________________
Boredom Software

Top Post subject: Re: RC4 Encryption Posted: Fri May 04, 2012 2:38 pm Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
I guess I am missing something because it does not work for me.
Below is the code I've tried and am not sure I have it right.
The RC4 method requires 2 bits of information so I pass it
C and M.

Where am I screwing this up ?

`Dim C, M, Data1, Data2 As stringC = "Password"M = "11111111-22222222"'This seems to encrypt fine'Call to RC4 methodData1 = RC4(M, C)MsgBox Data1'This just encrypts it again (not decrypting)'Call to RC4 methodData2 = RC4(C, M)MsgBox Data2`

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac

Top Post subject: Re: RC4 Encryption Posted: Fri May 04, 2012 4:22 pm Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
Found the error of my ways.

`Dim C, M, Data1, Data2 As stringC = "Password"M = "11111111-22222222"'This seems to encrypt fine'Call to RC4 methodData1 = RC4(M, C)MsgBox Data1'This Now Decrypts fine'Call to RC4 methodData2 = RC4(Data1, C)MsgBox Data2`

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac

Top Post subject: Re: RC4 Encryption Posted: Mon May 07, 2012 8:45 pm  Joined: Wed Sep 20, 2006 5:12 pm
Posts: 680
Location: Puerto Rico
you can look to sql to fined the encrypt data in the SqliteDB

_________________
Thanks for any contribution and God blesses all (I start Using RS in 10/12/2010)
Mac Mini with Lion v10.7.5 and Real Studio 2012r1 Pro And Windows 7 RS2012r1 Personal and Linux RS2012r1 Personal Register user
my Hobbies R/C Turbines Jets Models

Top Post subject: Re: RC4 Encryption Posted: Tue May 08, 2012 1:28 am  Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Hi jerryab,
jerryab wrote:
Found the error of my ways.

`Dim C, M, Data1, Data2 As stringC = "Password"M = "11111111-22222222"'This seems to encrypt fine'Call to RC4 methodData1 = RC4(M, C)MsgBox Data1'This Now Decrypts fine'Call to RC4 methodData2 = RC4(Data1, C)MsgBox Data2`

I have also tried that function. That method working fine with a string. But when I store the "Data1" in a textfield, surprisingly In textfield I got the value different from "Data1".

I can't understand why this things happening. Does anyone have an idea about it?

thanks

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7

Top Post subject: Re: RC4 Encryption Posted: Fri May 11, 2012 11:06 am Joined: Thu Dec 02, 2010 10:17 pm
Posts: 75
The text field probably has some invisible characters at the end of the stream that are being encrypted too so it appears to be different.

Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending  Page 1 of 2 [ 16 posts ] Go to page 1, 2  Next

 All times are UTC - 5 hours

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons 