It is currently Wed Nov 20, 2019 8:52 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: RC4
PostPosted: Sat Jan 15, 2005 3:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Jul 28, 2004 8:38 am
Posts: 175
PB wrote:
and it appears that Paul's lib is therefore returning the correct encrypted values.


I don't think so, though the problem is minor - Paul's lib returns 2 characters too much I think.

I can't try it, but I think the lib will return always a "00"+chr(0) at the end, with the "00" being too much.

Len(input)=Len(output)/2 is a must in stream ciphers, when the output is the hexa representation of the values.


Top
 Profile  
Reply with quote  
 Post subject: Re: RC4
PostPosted: Sat Jan 15, 2005 3:45 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> Paul's lib returns 2 characters too much I think

In my example it returns 4 extra characters. I've just noticed that Pille has
a memory-based routine -- don't know why I missed it before! Going crazy.
I'll play with that and see how it compares with Paul's lib then.

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject: Re: RC4
PostPosted: Sat Jan 15, 2005 3:47 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Jul 28, 2004 8:38 am
Posts: 175
PB wrote:
> Paul's lib returns 2 characters too much I think

In my example it returns 4 extra characters. I've just noticed that Pille has
a memory-based routine -- don't know why I missed it before! Going crazy.
I'll play with that and see how it compares with Paul's lib then.


Can't agree to that (though I am just rationalizing). Paul's lib returns 4 charachters more than Pille's procedure, but wrong is just the last 2 characters. The "00" in the middle are correct, which Pille's output lack.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jan 15, 2005 10:27 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 918
Location: Canada
The RC4Lib teminates the string with Hex $00

That is why in the example I posted, I did this...
Debug Left(CryptString(test,Key),Len(test)*2)

Which returns the string minus the $00

This is not a bug or mistake.
If you don't want to display the terminating $00 simply chop them off.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 17, 2005 3:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 443
Shannara wrote:
If there's a vb code counterpart to this code that produces the same, you'd be my hero.

Shannara,

I have a VB translation of the RC4 code. E-mail or PM me if you're still interested.

Regards,
Eric


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 13, 2008 6:56 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 25, 2004 2:37 pm
Posts: 233
Hello everybody !

Thanks for this great code. But how can make the RC4 procedure unicode compatible ?
I must crypt unicode text but that don't works

Thanks
Best regards

Thyphoon
ps:excuse me for my bad english


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 13, 2008 9:57 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 25, 2004 2:37 pm
Posts: 233
I think there is a bug try this

Code:

ProcedureDLL.s RC4(Inp.s, Key.s)
   ;encoded.s = RC4("Message", "Password")
   ;decoded.s = RC4(encoded, "Password")
   Protected i.l, j.l, t.l, x.l, temp.w, Y.w, Outp.s
   Dim S.w(255)
   Dim K.w(255)
   i.l = 0 : j.l = 0 : t.l = 0 : x.l = 0
   temp.w = 0 : Y.w = 0
   Outp.s = ""
   
    For i = 0 To 255
        S(i) = i
    Next
   
    j = 1
    For i = 0 To 255
        If j>Len(key)
            j = 1
        EndIf
        K(i) = Asc(Mid(key, j, 1))
        j = j + 1
    Next i
   
    j = 0
    For i = 0 To 255
        j = (j + S(i) + K(i)) & 255
        temp = S(i)
        S(i) = S(j)
        S(j) = temp
    Next i
   
    i = 0
    j = 0
    For x = 1 To Len(Inp)
        i = (i + 1) & 255
        j = (j + S(i)) & 255
        temp = S(i)
        S(i) = S(j)
        S(j) = temp
        t = (S(i) + (S(j) & 255)) & 255
        Y = S(t)
        Outp = Outp + Chr(Asc(Mid(Inp, x, 1)) ! Y)
    Next
   ProcedureReturn Outp
EndProcedure

ProcedureDLL.s CryptText(Text.s, Key.s)
   
   ProcedureReturn RC4(Text.s, Key)
EndProcedure

ProcedureDLL.s DeCryptText(Text.s, Key.s)
   ProcedureReturn RC4(Text.s, Key)
EndProcedure

code.s="QZARM69HMA8ZKB"
Debug code
crypt.s = CryptText(code, "16384")
Debug crypt
Debug DeCryptText(crypt, "16384")


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Sep 14, 2008 2:38 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> I think there is a bug

No bug. You can't do an RC4 routine without using the memory commands,
because RC4 uses byte 0 in some conversions. As your code doesn't have
any memory commands, it's not usable for RC4 at all.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Sep 14, 2008 7:25 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 25, 2004 2:37 pm
Posts: 233
Ok thanks :? !
I search an idea to crypt text withless use memory command, because i must put the crypt text in Sqlite database, and purebasic don't support Blob field !

best regards

Thy


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Sep 14, 2008 6:21 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 918
Location: Canada
RC4 lib works with Unicode, you could give that a try...
http://www.reelmedia.org/cgi-bin/PurePr ... &sub=ASM42

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Sep 14, 2008 6:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 25, 2004 2:37 pm
Posts: 233
Paul wrote:
RC4 lib works with Unicode, you could give that a try...
http://www.reelmedia.org/cgi-bin/PurePr ... &sub=ASM42

Thanks but i dont like user libs, Because i don't know if the libs will be updated for next purebasic version. And my application must run on Linux, MacOsX and Windows. I prefer to have all in purebasic Code. :wink:
I have found a solution on the german forum.
:D
Thanks to answer me :D ,

Thy


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 07, 2009 12:09 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3113
Location: United Kingdom
Have you a link to the solution you found?

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 07, 2009 12:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 25, 2004 2:37 pm
Posts: 233
DoubleDutch wrote:
Have you a link to the solution you found?

I forget the link ! but if you want the code ...
Code:
Procedure.l RC4Mem(Mem.l, memLen.l, key.s) ;rückgabe = adresse des vrschlüsselten speichers
   ; RC4 Verschlüsselung >30MB/s
   Protected i.l, t.l, x.l, j.l, temp.l, y.l, l.l, *Sp.Long, *KeyP.Byte, *Memm.Byte
   If key<>""
      Dim S.l(255)
      Dim K.l(255)
      i = 0 : j = 0 : t = 0 : x = 0
      temp = 0 : y = 0
      j = 1
      l.l = Len(key)
      *Sp = @S()
      *KeyP = @key
      For i = 0 To 255
         *Sp\l = i
         *Sp + 4
         If *KeyP\b = 0
            *KeyP = @key
         EndIf
         K(i) = *KeyP\b
         *KeyP + 1
      Next i
      j = 0
      For i = 0 To 255
         j = (j + S(i) + K(i)) & 255
         temp = S(i)
         S(i) = S(j)
         S(j) = temp
      Next i
      i = 0
      j = 0
      *Memm = Mem
      For x = 0 To memLen-1
         i = (i + 1) & 255
         j = (j + S(i)) & 255
         ;temp = S(i)
         ;S(i) = S(j)
         ;S(j) = temp
         Swap S(i), S(j)
         t = (S(i) + (S(j) & 255)) & 255
         y = S(t)
         *Memm\b ! y
         *Memm + 1
      Next
      ProcedureReturn Mem
   EndIf
   ProcedureReturn 0
EndProcedure
ProcedureDLL.s CryptText(string.s, Key.s)
   Protected strlen.l, enc.s, *codetmem
   strlen = StringByteLength(string)
   enc.s = Space(Int(strlen*1.35))
   *codetmem = RC4Mem(@string, strlen, key)
   Base64Encoder(*codetmem, strlen, @enc, strlen*1.35)
   ProcedureReturn enc
EndProcedure

ProcedureDLL.s DeCryptText(string.s, Key.s)
   Protected strlen.l, dec.s, decoutp.s, str2len.l, *decodetmem
   strlen = StringByteLength(string)
   dec.s = Space(Int(strlen*0.75))
   str2len.l = Base64Decoder(@string, strlen, @dec, strlen*0.75)
   *decodetmem = RC4Mem(@dec, str2len, key)
   decoutp.s = PeekS(*decodetmem, str2len)
   ProcedureReturn decoutp.s
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 07, 2009 2:05 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8006
Location: Fort Nelson, BC, Canada
Quote:
I forget the link !

It's best to stick with original authors if at all possible.

http://www.purebasic.fr/german/viewtopic.php?t=11347

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jun 07, 2009 2:15 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3113
Location: United Kingdom
Thanks. :)

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye