home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Server_Key3610311192001.psc / frmCreateKey.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-11-16  |  6.5 KB  |  217 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
  4. Begin VB.Form frmCreateKey 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Create Key"
  7.    ClientHeight    =   4470
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   3030
  11.    LinkTopic       =   "Form2"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4470
  15.    ScaleWidth      =   3030
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin RichTextLib.RichTextBox rtbSave 
  18.       Height          =   255
  19.       Left            =   1920
  20.       TabIndex        =   12
  21.       Top             =   4800
  22.       Visible         =   0   'False
  23.       Width           =   255
  24.       _ExtentX        =   450
  25.       _ExtentY        =   450
  26.       _Version        =   393217
  27.       TextRTF         =   $"frmCreateKey.frx":0000
  28.    End
  29.    Begin MSComDlg.CommonDialog cdMain 
  30.       Left            =   1080
  31.       Top             =   4680
  32.       _ExtentX        =   847
  33.       _ExtentY        =   847
  34.       _Version        =   393216
  35.    End
  36.    Begin VB.CommandButton cmdExit 
  37.       Caption         =   "E&xit"
  38.       Height          =   375
  39.       Left            =   240
  40.       TabIndex        =   9
  41.       Top             =   3840
  42.       Width           =   1095
  43.    End
  44.    Begin VB.Frame Frame2 
  45.       Caption         =   "Output"
  46.       Height          =   1095
  47.       Left            =   120
  48.       TabIndex        =   6
  49.       Top             =   2400
  50.       Width           =   2775
  51.       Begin VB.TextBox txtLK 
  52.          Height          =   285
  53.          Left            =   120
  54.          TabIndex        =   8
  55.          Top             =   600
  56.          Width           =   2535
  57.       End
  58.       Begin VB.Label Label3 
  59.          Caption         =   "Licence Key"
  60.          Height          =   255
  61.          Left            =   120
  62.          TabIndex        =   7
  63.          Top             =   360
  64.          Width           =   2295
  65.       End
  66.    End
  67.    Begin VB.Frame Frame1 
  68.       Caption         =   "Input"
  69.       Height          =   2175
  70.       Left            =   120
  71.       TabIndex        =   0
  72.       Top             =   120
  73.       Width           =   2775
  74.       Begin VB.TextBox txtLN 
  75.          Height          =   285
  76.          Left            =   120
  77.          TabIndex        =   5
  78.          Text            =   "1"
  79.          Top             =   1200
  80.          Width           =   2535
  81.       End
  82.       Begin VB.CommandButton cmdCreate 
  83.          Caption         =   "Create Key"
  84.          Default         =   -1  'True
  85.          Height          =   375
  86.          Left            =   1560
  87.          TabIndex        =   3
  88.          Top             =   1680
  89.          Width           =   1095
  90.       End
  91.       Begin VB.TextBox txtSerialNum 
  92.          Height          =   285
  93.          Left            =   120
  94.          TabIndex        =   2
  95.          Top             =   600
  96.          Width           =   2535
  97.       End
  98.       Begin VB.Label Label2 
  99.          Caption         =   "No. Of Licences"
  100.          Height          =   255
  101.          Left            =   120
  102.          TabIndex        =   4
  103.          Top             =   960
  104.          Width           =   2535
  105.       End
  106.       Begin VB.Label Label1 
  107.          Caption         =   "Client UID"
  108.          Height          =   255
  109.          Left            =   120
  110.          TabIndex        =   1
  111.          Top             =   360
  112.          Width           =   975
  113.       End
  114.    End
  115.    Begin VB.Frame Frame3 
  116.       Height          =   735
  117.       Left            =   120
  118.       TabIndex        =   10
  119.       Top             =   3600
  120.       Width           =   2775
  121.       Begin VB.CommandButton cmdSave 
  122.          Caption         =   "&Save Key"
  123.          Height          =   375
  124.          Left            =   1560
  125.          TabIndex        =   11
  126.          Top             =   240
  127.          Width           =   1095
  128.       End
  129.    End
  130. Attribute VB_Name = "frmCreateKey"
  131. Attribute VB_GlobalNameSpace = False
  132. Attribute VB_Creatable = False
  133. Attribute VB_PredeclaredId = True
  134. Attribute VB_Exposed = False
  135. Dim s(0 To 255) As Integer 'S-Box
  136. Dim kep(0 To 255) As Integer
  137. Dim i As Integer, j As Integer
  138. Public Sub RC4ini(Pwd As String)
  139.     Dim temp As Integer, a As Integer, b As Integer
  140.     'Save Password in Byte-Array
  141.     b = 0
  142.     For a = 0 To 255
  143.         b = b + 1
  144.         If b > Len(Pwd) Then
  145.             b = 1
  146.         End If
  147.         kep(a) = Asc(Mid$(Pwd, b, 1))
  148.     Next a
  149.     'INI S-Box
  150.     For a = 0 To 255
  151.         s(a) = a
  152.     Next a
  153.     b = 0
  154.     For a = 0 To 255
  155.         b = (b + s(a) + kep(a)) Mod 256
  156.         ' Swap( S(i),S(j) )
  157.         temp = s(a)
  158.         s(a) = s(b)
  159.         s(b) = temp
  160.     Next a
  161. End Sub
  162. Public Function EnDeCrypt(plaintxt As Variant) As Variant
  163.     Dim temp As Integer, a As Long, i As Integer, j As Integer, k As Integer
  164.     Dim cipherby As Byte, cipher As Variant
  165.     For a = 1 To Len(plaintxt)
  166.         i = (i + 1) Mod 256
  167.         j = (j + s(i)) Mod 256
  168.         ' Swap( S(i),S(j) )
  169.         temp = s(i)
  170.         s(i) = s(j)
  171.         s(j) = temp
  172.         'Generate Keybyte k
  173.         k = s((s(i) + s(j)) Mod 256)
  174.         'Plaintextbyte xor Keybyte
  175.         cipherby = Asc(Mid$(plaintxt, a, 1)) Xor k
  176.         cipher = cipher & Chr(cipherby)
  177.     Next a
  178.     EnDeCrypt = cipher
  179. End Function
  180. Private Sub cmdCreate_Click()
  181.     If txtSerialNum = "" Then
  182.         MsgBox "Client UID must have valid data!", vbExclamation + vbOKOnly, "Error"
  183.         Exit Sub
  184.     End If
  185.     RC4ini (txtSerialNum)
  186.     Randomize
  187.     a1 = Int(Rnd * 88888888) + 11111111
  188.     a = Hex(a1)
  189.     b = Asc(Right(a, 1))
  190.     d = Asc(Left(a, 1))
  191.     qw = Asc(Mid(a, 2, 1))
  192.     c = ((Val(txtLN) * b) * d) + Asc(Mid(a, 2, 1))
  193.     txtLK = EnDeCrypt(c & " " & a1)
  194. End Sub
  195. Private Sub cmdExit_Click()
  196.     Unload Me
  197. End Sub
  198. Private Sub cmdSave_Click()
  199.     cdMain.FileName = ""
  200.     cdMain.Filter = "*.dlk|*.dlk"
  201.     cdMain.ShowSave
  202.     If cdMain.FileName <> "" Then
  203.         Randomize
  204.         rtbSave.Text = Len(txtLK)
  205.         For i = 1 To 35
  206.             a = Int(Rnd * 250) + 1
  207.             rtbSave.Text = rtbSave.Text & Chr(a)
  208.         Next i
  209.         rtbSave.Text = rtbSave.Text & txtLK
  210.         For i = 1 To 35
  211.             a = Int(Rnd * 250) + 1
  212.             rtbSave.Text = rtbSave.Text & Chr(a)
  213.         Next i
  214.         rtbSave.SaveFile cdMain.FileName, rtfText
  215.     End If
  216. End Sub
  217.