VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet.

by Patterson Programming (5 Submissions)
Category: Encryption
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Sat 22nd July 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet.

Rate OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet.



Option Explicit

Dim DataLen&, DataBuffer() As Byte

'* assume 128-bit key
Const SessionKeyLen = 16
Dim SessionKey(15) As Byte

'* use static numeric arrays
'* easier to clean up
Dim Permutation%(255), LongKey%(255)
Dim ii%, jj%

Sub main ()

    'SessionKey(0..15) = ?

    '* make the permutation
    OurSeeFourKey

    'DataLen& = ?
    ReDim DataBuffer(DataLen& - 1) As Byte

    'DataBuffer(0..?) = ? (COPY IN THE PLAINTEXT)

    '* do the encryption
    ii% = 0: jj% = 0
    OurSeeFourCipher

End Sub


Sub OurSeeFourKey()

    Dim i%, j%

    '* initialize Permutation vector array *
    For i% = 0 To 255
        Permutation%(i%) = i%
    Next

    '* replicate session key into the LongKey array *
    j% = 0
    For i% = 0 To 255
        LongKey%(i%) = SessionKey(j%)
        j% = (j% + 1) Mod SessionKeyLen
    Next

    '* randomize Permutation vector *
    j% = 0
    For i% = 0 To 255

        '* for efficiency, use &HFF rather than Mod *
        j% = (j% + Permutation%(i%) + LongKey%(i%)) And &HFF
        SWAP Permutation%(i%), Permutation%(j%)
    Next

    '* this is added to the original RC4 (tm) algorithm
    '* to prevent some attacks
    For i% = 0 To 255
        j% = (j% + Permutation%(i%)) And &HFF
       SWAP Permutation%(i%), Permutation%(j%)
    Next

End Sub


Static Sub OurSeeFourCipher()

    Dim x&, IndexByte As Byte, CipherByte As Byte

    For x& = 0 To DataLen& - 1

        ii% = (ii% + 1) And &HFF
        jj% = (jj% + Permutation%(ii%)) And &HFF
        SWAP Permutation%(ii%), Permutation%(jj%)

        IndexByte = (Permutation%(ii%) + Permutation%(jj%)) And &HFF
        CipherByte = Permutation%(IndexByte) And &HFF

        DataBuffer(x&) = DataBuffer(x&) Xor CipherByte

    Next

End Sub


Private Sub SWAP(a%, b%)

    Dim y%

    y% = a%: a% = b%: b% = y%

End Sub


Download this snippet    Add to My Saved Code

OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet. Comments

No comments have been posted about OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet.. Why not be the first to post a comment about OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher. Code snippet..

Post your comment

Subject:
Message:
0/1000 characters