Make Your Own KeyGen with Visual Basic (by 4ntipatika)

Note : THIS TUTORIAL IS FOR EDUCATIONAL PURPOSES ONLY. I SHARED IT FOR YOU TO HELP YOU BOOST YOUR CODING/PROGRAMMING SKILLS.


Most commercial software uses some form of random keys to authenticate and register a legitimate copy when the program is installed. Commonly this is a series of random letters grouped in varying numbers of letters. For example, you might see this sequence DXUWB-GPHQE-CCNYQ-QFHAT-ZFBLO on a licensed program.

Specialized software called Key Generators or KeyGen creates these codes, but you can make your own using only 16 lines of a Visual Basic Codes (Awesome right , but this is just an example / demonstration).


So Let's Start !

  • Start a new project in Visual Basic selecting the "Standard.EXE" template from the list offered under "File" and "New Project". Click on "File" , "Save Project  as"  and name both the form and project when prompted. For Example , I named it to "MyKeyGen".

  • Add a "CommandButton" control to the open form by double clicking this control in the Toolbox on the left of your screen. This control is an icon shaped like a small rectangle. Normally it is the third control down in the right hand column of the ToolBox. Add a label to the form in the same way. The label icon is a large letter "A" in the toolbox.

  • Click on the new "Command1" button now on the form to focus on its properties in the"Properties" panel on the right. Double click on the "(Name)" property to highlight the default name, "Command1". Change this name to "KeyGen". Click on the caption property and change it to "Generate Key". Click on the new "Label1" on the form and make these changes to its properties:
Delete the Caption name.
Scroll down in the properties list until you find "Height" and change this to 500.
Scroll to the bottom of the properties and change the "Width" to 1200.

  • Click on "View" in the main Visual Basic menu at the top and choose "Code". This opens the Code window where you should type these lines exactly as they appear:
Option Base 1
Option Explicit
Private Sub KeyGen_Click()
Dim n As Integer
im KeyGen(26) As Long
Dim NewKey, FinalKey As String
Randomize
For n = 1 To 26
KeyGen(n) = Int(Rnd * 26) + 1
eyGen(n) = KeyGen(n) + 64
NewKey = Chr$(KeyGen(n))
FinalKey = FinalKey + NewKey
Next
FinalKey = Left(FinalKey, 5) + "-" + Mid(FinalKey, 6, 5) + &"-" + Mid(FinalKey, 11, 5) + "-" + Mid(FinalKey, 17, 5)
Label1.Caption = FinalKey
End Sub

  • Save the project by clicking on "File" and "Save Project". Press "F5" to run the program. 
Declarations of the lines used in code :
"Dim" specify how the program variables are used.
"KeyGen(26)" creates an array of variables with 26 possibilities.
"Option Base 1" ensures the first of the 26 is numbered one.
"Randomize" generates a new random seed each time the program runs.
The rest of the lines create a series of random numbers which are then converted to letters. Since ASCII code for the alphabet begins with ASCII 65, we have to add 64 to each random number before the conversion. In the end, a list of four sets of random letters separated by hyphens is created and displayed in the label box.



>>> MUST READ TIPS AND WARNINGS

  • If you need a longer series of key letters, add an additional segment to the end of the line beginning "Final Key = Left(Finalkey,5)". Insert at the end of this line the following code: 
+ "-" + Right(FinalKey,5)
  • To create four letter sequences, or vary the number of letters in each group, change the fives in the FinalKey line to other numbers.
  • Using ARRAYS can be TRICKY, particularly when you set a limit on the maximum number and use repeating sequences. If you get a message "Run-time error 9, subscript out of range" it means you entered a larger number in one of the lines than the array can hold.
Enjoy coding!

Credits: 4nti
Share on Google Plus

About Blurffy

Just another internet folk who want to share random softwares, movies and any kind of things in the internet.
    Blogger Comment

0 comments:

Post a Comment