RC4 Encryption (byte ptr's)

BlitzMax Forums/BlitzMax Programming/RC4 Encryption (byte ptr's)

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

That was suprisingly simple... (thanks for the pointers, I always use SuperStrict, and found the :<type> to be much easier - never bothered learning them)
It modifies the data directly now :)
Function RC4_Bytes(inp:Byte Ptr, count:Int, key:String) 
  If inp = Null Then Return
    Local S:Int[512 + Ceil(count *.55)] 
    Local i:Int, j:Int, t:Int, X:Int
    'Local outbuf:Byte Ptr = Byte Ptr(VarPtr s[512] ) 
    
    j = 0
    For i = 0 To 255
        S[i] = i
        If j > (key.Length - 1) Then
            j = 0
        EndIf
        S[256 + i] = key[j] & $ff
       j:+1
    Next
    
    j = 0
    For i = 0 To 255
        j = (j + S[i] + S[256 + i] ) & $ff
        t = S[i] 
        S[i] = S[j] 
        S[j] = t
    Next
    
    i = 0
    j = 0
    For Local X:Int = 0 To count - 1
        i = (i + 1) & $ff
        j = (j + S[i] ) & $ff
        t = S[i] 
        S[i] = S[j] 
        S[j] = t
        t = (S[i] + S[j] ) & $ff
        inp[X] = (inp[X] ~ S[t] ) 
    Next
    
 'Return outbuf
 
End Function