VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Flexgen CRP V1.0"
   ClientHeight    =   1095
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4035
   Icon            =   "CRP.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   1095
   ScaleWidth      =   4035
   StartUpPosition =   2  'CenterScreen
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   1860
      TabIndex        =   3
      Text            =   "Combo1"
      Top             =   720
      Width           =   1935
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Exit"
      Height          =   495
      Left            =   2700
      TabIndex        =   2
      Top             =   120
      Width           =   1155
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Crypt"
      Height          =   495
      Left            =   1440
      TabIndex        =   1
      Top             =   120
      Width           =   1155
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Decrypt"
      Height          =   495
      Left            =   180
      TabIndex        =   0
      Top             =   120
      Width           =   1155
   End
   Begin VB.Label Label1 
      Caption         =   "Database Version"
      Height          =   195
      Left            =   300
      TabIndex        =   4
      Top             =   780
      Width           =   1395
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
versionedatabase = Combo1.Text

filen = FreeFile
Open App.Path + "\FLEXGEN.INI" For Input As filen
filen1 = FreeFile
Open App.Path + "\FLEXGEN.DEC" For Output As filen1
Line Input #filen, dummy
versionedb = RTrim(Right(dummy, Len(dummy) - 10))

If versionedb = versionedatabase + "D" Then
    MsgBox "Database Already Decrypted", vbCritical, "Error"
    GoTo finex
End If

If versionedb <> versionedatabase Then
    MsgBox "Wrong Database Version", vbCritical, "Error"
    GoTo finex
End If

Print #filen1, "DBVersion=" + versionedb + "D"

While Not EOF(filen)
    Line Input #filen, dummy
    
    If Left(UCase(dummy), 5) = "KEY1=" Then
        cKEY1 = Right(dummy, Len(dummy) - 5)
        mKEY1 = "&H" + decrypt(cKEY1)
        KEY1 = Hex(mKEY1 Xor &H9112A6C3)
        Print #filen1, "Key1=" + fill(KEY1)
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY2=" Then
        cKEY2 = Right(dummy, Len(dummy) - 5)
        mKEY2 = "&H" + decrypt(cKEY2)
        KEY2 = Hex(mKEY2 Xor &H42522D24)
        Print #filen1, "Key2=" + fill(KEY2)
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY3=" Then
        cKEY3 = Right(dummy, Len(dummy) - 5)
        mKEY3 = "&H" + decrypt(cKEY3)
        KEY3 = Hex(mKEY3 Xor &HA3CDEF90)
        Print #filen1, "Key3=" + fill(KEY3)
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY4=" Then
        cKEY4 = Right(dummy, Len(dummy) - 5)
        mKEY4 = "&H" + decrypt(cKEY4)
        KEY4 = Hex(mKEY4 Xor &H192F3745)
        Print #filen1, "Key4=" + fill(KEY4)
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY5=" Then
        cKEY5 = Right(dummy, Len(dummy) - 5)
        mKEY5 = "&H" + decrypt(cKEY5)
        KEY5 = Hex(mKEY5 Xor &HA0B9C8D7)
        Print #filen1, "Key5=" + fill(KEY5)
        GoTo nowr
    End If
    If Left(UCase(dummy), 6) = "SEED1=" Then
        cseed1 = Right(dummy, Len(dummy) - 6)
        mseed1 = "&H" + decrypt(cseed1)
        seed1 = Hex(mseed1 Xor &H1199AABB)
        Print #filen1, "Seed1=" + fill(seed1)
        GoTo nowr
    End If
    If Left(UCase(dummy), 6) = "SEED2=" Then
        cseed2 = Right(dummy, Len(dummy) - 6)
        mseed2 = "&H" + decrypt(cseed2)
        seed2 = Hex(mseed2 Xor &H5529DF4E)
        Print #filen1, "Seed2=" + fill(seed2)
        GoTo nowr
    End If
    If Left(UCase(dummy), 7) = "VENDOR=" Then
        cvendor = Right(dummy, Len(dummy) - 7)
        vendor = decrypt(cvendor)
        Print #filen1, "Vendor=" + vendor
        GoTo nowr
    End If
    
        Print #filen1, dummy
nowr:
Wend
    Close #filen
    Close #filen1
    FileCopy App.Path + "\FLEXGEN.INI", App.Path + "\FLEXGEN.BAK"
    FileCopy App.Path + "\FLEXGEN.DEC", App.Path + "\FLEXGEN.INI"
    MsgBox "Database Decrypted", vbInformation, "Success"
finex:
Close #filen
Close #filen1

End Sub

Private Sub Command2_Click()
versionedatabase = Combo1.Text

filen = FreeFile
Open App.Path + "\FLEXGEN.INI" For Input As filen
filen1 = FreeFile
Open App.Path + "\FLEXGEN.CRY" For Output As filen1
Line Input #filen, dummy
versionedb = RTrim(Right(dummy, Len(dummy) - 10))

If versionedb = versionedatabase Then
    MsgBox "Database Already Crypted", vbCritical, "Error"
    GoTo finex
End If

If versionedb <> versionedatabase + "D" Then
    MsgBox "Wrong Database Version", vbCritical, "Error"
    GoTo finex
End If

Print #filen1, "DBVersion=" + versionedatabase

While Not EOF(filen)
    Line Input #filen, dummy
    
    If Left(UCase(dummy), 5) = "KEY1=" Then
        cKEY1 = Right(dummy, Len(dummy) - 5)
        mKEY1 = Hex("&H" + cKEY1 Xor &H9112A6C3)
        KEY1 = crypt(mKEY1)
        Print #filen1, "Key1=" + KEY1
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY2=" Then
        cKEY2 = Right(dummy, Len(dummy) - 5)
        mKEY2 = Hex("&H" + cKEY2 Xor &H42522D24)
        KEY2 = crypt(mKEY2)
        Print #filen1, "Key2=" + KEY2
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY3=" Then
        cKEY3 = Right(dummy, Len(dummy) - 5)
        mKEY3 = Hex("&H" + cKEY3 Xor &HA3CDEF90)
        KEY3 = crypt(mKEY3)
        Print #filen1, "Key3=" + KEY3
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY4=" Then
        cKEY4 = Right(dummy, Len(dummy) - 5)
        mKEY4 = Hex("&H" + cKEY4 Xor &H192F3745)
        KEY4 = crypt(mKEY4)
        Print #filen1, "Key4=" + KEY4
        GoTo nowr
    End If
    If Left(UCase(dummy), 5) = "KEY5=" Then
        cKEY5 = Right(dummy, Len(dummy) - 5)
        mKEY5 = Hex("&H" + cKEY5 Xor &HA0B9C8D7)
        KEY5 = crypt(mKEY5)
        Print #filen1, "Key5=" + KEY5
        GoTo nowr
    End If
    If Left(UCase(dummy), 6) = "SEED1=" Then
        cseed1 = Right(dummy, Len(dummy) - 6)
        mseed1 = Hex("&H" + cseed1 Xor &H1199AABB)
        seed1 = crypt(mseed1)
        Print #filen1, "Seed1=" + seed1
        GoTo nowr
    End If
    If Left(UCase(dummy), 6) = "SEED2=" Then
        cseed2 = Right(dummy, Len(dummy) - 6)
        mseed2 = Hex("&H" + cseed2 Xor &H5529DF4E)
        seed2 = crypt(mseed2)
        Print #filen1, "Seed2=" + seed2
        GoTo nowr
    End If
    If Left(UCase(dummy), 7) = "VENDOR=" Then
        cvendor = Right(dummy, Len(dummy) - 7)
        vendor = crypt(cvendor)
        Print #filen1, "Vendor=" + vendor
        GoTo nowr
    End If
    
        Print #filen1, dummy
nowr:
Wend
    Close #filen
    Close #filen1
    FileCopy App.Path + "\FLEXGEN.INI", App.Path + "\FLEXGEN.BAK"
    FileCopy App.Path + "\FLEXGEN.CRY", App.Path + "\FLEXGEN.INI"
    MsgBox "Database Crypted", vbInformation, "Success"
finex:
Close #filen
Close #filen1

End Sub

Private Sub Command3_Click()
Unload Me
End
End Sub

Private Sub Form_Load()
Form2.Show 1
Combo1.Clear
Combo1.AddItem "5.0"
Combo1.AddItem "6.0"
Combo1.AddItem "7.0"
Combo1.ListIndex = 0
End Sub
Private Function decrypt(stringa) As String
usci = ""
For r = 1 To Len(stringa)
    a = Asc(Mid(stringa, r, 1)) - 30 - r
    usci = usci + Chr(a)
Next r
decrypt = usci
End Function
Private Function fill(stringa) As String
If Len(stringa) = 1 Then fill = "0000000" + stringa: Exit Function
If Len(stringa) = 2 Then fill = "000000" + stringa: Exit Function
If Len(stringa) = 3 Then fill = "00000" + stringa: Exit Function
If Len(stringa) = 4 Then fill = "0000" + stringa: Exit Function
If Len(stringa) = 5 Then fill = "000" + stringa: Exit Function
If Len(stringa) = 6 Then fill = "00" + stringa: Exit Function
If Len(stringa) = 7 Then fill = "0" + stringa: Exit Function
fill = stringa
End Function

Private Function crypt(stringa) As String
usci = ""
For r = 1 To Len(stringa)
    a = Asc(Mid(stringa, r, 1)) + 30 + r
    usci = usci + Chr(a)
Next r
crypt = usci
End Function

