Generating Random Alpha and Numeric characters

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Any one have a code snippet that would show me how to:

1. Generate a 24 character
2. Random
3. Alpha Numeric data dump
4. into an array


IE.

1adftredbgRtwbertagUnrew
123456fdsgui8tghjiioojjj

I'm going to hard code the values into my app as a poormans
alternative to buying registation software for my vb.net programs.
I'll encrypt and ofusicate the code to make things fairly timely to
crack.
 
i could do it with time...which I don't have atm...but I will say this. Do NOT
store any information as static strings that you don't want a user to read!!! I
wrote a security component with public/private keys to ensure that the libraries
loading this component was indeed one I wrote. I found that by opening up the
component's dll in a text editor (IE: NOTEPAD), I was able to READ the private
key in plain English!!! So remember, do NOT store any of the registration keys
inside the DLL as plain text...

Our workaround was simple, modified the text into a numeric value that
represented each letter and made it into an array. Therefore, not even a hex
editor could be used to read the information :) (By obfuscating the code, it
would only slow down the non-determined hacker...obfuscating just turns something
from English/language to jumble...which can still be followed if a hacker is
good).

Mythran
 
Could someone post some code? Even a small hint in the right
direction would be appreciated.
 
Dim rd As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod
Integer.MaxValue))

Dim ch() As Char = {"A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c, "H"c, "I"c,
"J"c, "K"c, "L"c, "M"c, "O"c, "P"c, "Q"c, "R"c, "S"c, "T"c, "U"c, "V"c,
"W"c, "X"c, "Y"c, "Z"c, "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c,
"i"c, "j"c, "k"c, "l"c, "m"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c,
"v"c, "w"c, "x"c, "y"c, "z"c, "0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c,
"7"c, "8"c, "9"c}

Private Function CreateRandomString() As String

Dim i As Integer
Dim number As Integer = rd.Next(4, 12)
Dim str As New System.Text.StringBuilder

For i = 0 To number
str.Append(ch(rd.Next(0, ch.Length)))
Next

Return str.ToString

End Function
 
Thank you.

If you don't mind me asking...:

The lower case c after the "A", "B"'s... what does it stand for.... I
have never seen this type of declaring.

I'll read up on the string builder class. Thank you again.

-Peter
 
It means that it's a Char and not a string. If you omit it, you'll get an
error.
 
Could someone post some code? Even a small hint in the right
direction would be appreciated.

Option Strict On
Option Explicit On

Imports System.Text

Module Module1

Sub Main()
Dim bytes(23) As Byte
Dim rnd As New Random

For i As Integer = 0 To 23
Select Case rnd.Next(0, 3)
Case 0
bytes(i) = CByte(rnd.Next(48, 58))
Case 1
bytes(i) = CByte(rnd.Next(65, 91))
Case 2
bytes(i) = CByte(rnd.Next(97, 123))
End Select
Next

Console.WriteLine(Encoding.ASCII.GetString(bytes))
End Sub

End Module

Here you go...
 
Any one have a code snippet that would show me how to:

1. Generate a 24 character
2. Random
3. Alpha Numeric data dump
4. into an array


IE.

1adftredbgRtwbertagUnrew
123456fdsgui8tghjiioojjj

I'm going to hard code the values into my app as a poormans
alternative to buying registation software for my vb.net programs.
I'll encrypt and ofusicate the code to make things fairly timely to
crack.

Peter,

I would suggest, if you really need a unique id - that you use a GUID
for this... It is a few more then 24 characters, but it is guarenteed*
to be unique.

Dim id As String = Guid.NewGuid().ToString("N")
Console.WriteLine(id)

In this format you get a 32 characther string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top