Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
OurSeeFour stream cipher. Based on the alleged RC4...
Author:
Patterson Programming
E-mail:
Click to e-mail author
Submitted:
8/17/2000
Version:
VB5
Compatibility:
VB5, VB6
Category:
Security
Views:
10458
OurSeeFour stream cipher. Based on the alleged RC4(tm) cipher.
Declarations:
'Declarations included in the code.
Code:
Attribute VB_Name = "OurSeeFour" 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
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement