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
256bit Key Generator
Author:
David M. Lewis
E-mail:
Click to e-mail author
Submitted:
12/29/2012
Version:
VB6
Compatibility:
VB6
Category:
Security
Views:
7829
Generates a scrambled 256 byte key string, with no redundancy, based on a password as a seed. Use for encryption purposes.
Declarations:
'none
Code:
Public Function scram256(password As String) As String 'This function generates a 256 byte string containing every possible value from 0 to 255. It then 'scrambles it using a password which seeds the PRNG to swap bytes within the string. You can also 'use bytes from a previous generation to seed the next. Dim count As Integer Dim pcount As Integer Dim strkey As String Dim seed As Integer Dim r1 As Integer Dim r2 As Integer Dim c1 As String Dim c2 As String strkey = "" 'clear it. pcount = 0 For count = 0 To 255 'generate the default string... strkey = strkey & Chr(count) Next count For count = 1 To (128 + Asc(Left(password, 1))) ' 128 times minimum but more based on pw byte 1. pcount = pcount + 1 If pcount > Len(password) Then pcount = 1 seed = Asc(Mid(password, pcount, 1)) Randomize seed r1 = Int(Rnd * 256) + 1 'select random locations r2 = Int(Rnd * 256) + 1 c1 = Mid(strkey, r1, 1) 'get byte. c2 = Mid(strkey, r2, 1) 'get other byte. Mid(strkey, r1, 1) = c2 'swap the bytes.. Mid(strkey, r2, 1) = c1 Next count scram256 = strkey End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement