Sign in to follow this  
Followers 0
DreamVB

DM Create Serial keys for your software.

1 post in this topic

#1 ·  Posted (edited)

hi this is my little 2 cents of how to create a list of random list of serials you can use for your software.

Hope you may find it us full. Comments are welcome.

The code

#Region
#AutoIt3Wrapper_Change2CUI=y
#EndRegion
Local Enum $MaskAlpha = 0, $MaskDigits, $MaskAlphaNum

Func RandomPassword($Length, $Mask = $MaskAlpha)
    Local $buff
    Local $i
    Local $n
    Local $PwsBuff
    Const $AlphaU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Const $Digits = "0123456789"

    Switch $Mask
        Case $MaskAlpha
            $PwsBuff = $AlphaU
        Case $MaskDigits
            $PwsBuff = $Digits
        Case $MaskAlphaNum
            $PwsBuff = $AlphaU & $Digits
    EndSwitch

    ;This creates the random password.
    For $i = 1 To $Length
        ;Pick a random chat between 1 and the pwsMask Length
        $n = Int(Random(1, StringLen($PwsBuff)))
        ;Concat each chat that has been picked out of pwsMask to $buff
        $buff &= StringMid($PwsBuff, $n, 1)
    Next
    Return $buff
EndFunc   ;==>RandomPassword

Func CreateSerial($Cols, $CharsPerCol, $Rows, $Mask = $MaskAlpha, $ColSep = "-")
    Local $i, $n
    Local $Buffer

    For $n = 0 To $Rows - 1
        For $i = 0 To $Cols - 1
            $PwsSet = RandomPassword($CharsPerCol, $Mask)
            ;Build serial
            $Buffer &= $PwsSet & $ColSep
        Next
        ;Remove last $ColSep
        $Buffer = StringTrimRight($Buffer, 1) & @CRLF
    Next

    $PwsBuff = ""
    Return $Buffer
    $Buffer = ""
EndFunc   ;==>CreateSerial

Func Main()

    Local $Cols
    Local $CharPerCol
    Local $Rows
    Local $Mask
    Local $List

    $cmd = $CmdLine

    If UBound($cmd) < 4 Then
        ConsoleWrite("Incorrect syntext")
        Exit
    Else
        $Cols = $cmd[1]
        $CharPerCol = $cmd[2]
        $Rows = $cmd[3]
    EndIf

    If UBound($cmd) > 4 Then
        $Mask = $cmd[4]
    EndIf
    ;Create the random serials
    $List = CreateSerial($Cols, $CharPerCol, $Rows, $Mask, "-")
    ;Output list
    ConsoleWrite($List)
    ;Clear up
    $cmd = Null
    $List = Null
EndFunc   ;==>Main

;Call main func
Main()
 

Example batch to create the serials with the above code.

@ECHO OFF

REM cols the number of colums to create.
REM parts is the number of echo serial has.
REM is the number of rows to create.
REM 0 at the end if the format eg 0=Alpha,1=Digits,2=Alpha+Digits

set cols=5
set parts=5
set rows=10

SerialGen.exe %cols% %parts% %rows% 0 > serials.txt
exit
Edited by DreamVB

On Error Resume Pulling Hair Out.

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0