VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "DBCrypt V1.0"
   ClientHeight    =   765
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   2655
   Icon            =   "dbcrypt.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   765
   ScaleWidth      =   2655
   StartUpPosition =   2  'CenterScreen
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   1320
      Top             =   60
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Exit"
      Height          =   495
      Left            =   1380
      TabIndex        =   1
      Top             =   120
      Width           =   1155
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Crypt"
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   1155
   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()

End Sub

Private Sub Command2_Click()
versionedatabase = "4.0"

currdire = "C:\"
CommonDialog1.InitDir = currdire
ChDir (currdire)
ChDrive (currdire)
CommonDialog1.FileName = "FLEXGEN.INI"
CommonDialog1.Filter = "All Files (*.INI)|*.INI"
CommonDialog1.Action = 1
q1 = CommonDialog1.FileName
q2 = CommonDialog1.FileTitle
currdire = Left(q1, Len(q1) - Len(q2))
If q1 = "" Then GoTo nosave
If q1 = "FLEXGEN.INI" Then GoTo nosave


filen = FreeFile
Open q1 For Input As filen
filen1 = FreeFile
Open q1 + ".ENC" For Output As filen1
Line Input #filen, dummy
versionedb = RTrim(Right(dummy, Len(dummy) - 10))


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

Print #filen1, "DBVersion=6.0"

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 q1, q1 + ".BAK"
        FileCopy q1 + ".ENC", q1
        MsgBox "Database Crypted", vbInformation, "Success"
finex:

nosave:
End Sub

Private Sub Command3_Click()
Unload Me
End
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

