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
Smokescreen Hash Function
Author:
David M. Lewis
E-mail:
Click to e-mail author
Submitted:
9/1/2013
Version:
VB6, VB 2005, VB 2008, VB 2010, VB 2012
Compatibility:
VB6, VB 2005, VB 2008, VB 2010, VB 2012
Category:
Security
Views:
5304
This is a simple hash function with variable output length. It is meant for educational use. Great for novice encryption projects.
Declarations:
'none
Code:
Public Function SmokeScreen(indata As String) As String '(c) David M. Lewis, 2013. For private, non-commerical, non- govt use only! 'email: stmdk@hotmail.com 'Simple hash function. 'The output size is the same as the input. Max=65K 'We pair bytes and xor them with each other and xor to previous key. The result gets appended to a key string. 'Leftover byte is ignored if input is odd length. 'We then apply the key to the entire input via xor. 'The avalanche of this function is poor, especially if changes come late in the input, but its quick and dirty. Dim ilen As Integer Dim PTval As Integer Dim KEYval As Integer Dim lastKEYval As Integer Dim CTval As Integer Dim KEYstr As String Dim count As Integer Dim pairs As Integer ilen = Len(indata) 'First detrmine how many pairs.. pairs = Int(ilen / 2) 'This will drop any leftoever byte. For count = 1 To pairs Step 2 KEYval = Asc(Mid(indata, count, 1)) Xor Asc(Mid(indata, count + 1, 1)) Xor lastKEYval KEY = KEY & Chr(KEYval) lastKEYval = KEYval Next count 'the key is repeated, so let's just make it longer to avoid running out. KEY = KEY & KEY & KEY & KEY & KEY 'should be long enough. For count = 1 To ilen PTval = Asc(Mid(indata, count, 1)) KEYval = Asc(Mid(KEY, count, 1)) CTval = PTval Xor KEYval Mid(indata, count, 1) = Chr(CTval) Next count SmokeScreen = indata 'return it. End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement