Code encrypt data
Public Function cRC4(inp As String, key As String) As String On Error Resume Next
Dim s(0 To 255) As Byte, K(0 To 255) As Byte, i As Long Dim j As Long, temp As Byte, y As Byte, t As Long, x As Long Dim Outp As String
For i = 0 To 255 s(i) = i
Next j = 1
For i = 0 To 255
If j > Len(key) Then j = 1 K(i) = Asc(Mid(key, j, 1)) j = j + 1
Next i j = 0
For i = 0 To 255
j = (j + s(i) + K(i)) Mod 256 temp = s(i)
s(i) = s(j) s(j) = temp Next i i = 0 j = 0
For x = 1 To Len(inp) i = (i + 1) Mod 256 j = (j + s(i)) Mod 256 temp = s(i)
s(i) = s(j) s(j) = temp
t = (s(i) + (s(j) Mod 256)) Mod 256 y = s(t)
Outp = Outp & Chr(Asc(Mid(inp, x, 1)) Xor y) Next
cRC4 = Outp
Code browsing file
Option Explicit
Private Sub cmdBACK_Click() On Error Resume Next frmSTART.Show Unload Me End Sub
Private Sub cmdBROWSE_Click() On Error Resume Next
Dim obj As CDLG, fNAME As String Set obj = New CDLG
Me.CommonDialog1.ShowOpen nFile = Me.CommonDialog1.FileName fsFile = nFile
If nFile <> "" Then
Me.txtFILE.Text = nFile End If
'fFile = fNAME End Sub
Private Sub cmdCANCEL_Click() On Error Resume Next
Unload Me End Sub
Private Sub cmdNEXT_Click() On Error Resume Next Dim frm As frmPASSWORD 'Dim frm As Form1
Set frm = New frmPASSWORD 'Set frm = New Form1
frm.Show Unload Me End Sub
Private Sub txtFILE_Change() On Error Resume Next If txtFILE.Text = "" Then
Me.cmdNEXT.Enabled = False Else
Me.cmdNEXT.Enabled = True End If
End Sub
Code penyisipan data ke file encrypt, menghapus, membaca dan proses file
Public oPil As String Public nFile As String Public nPass As String Public fsFile As String Option Explicit
Dim AllFile As String Public TxtLen As String * 5 Public PassLen As String * 2 Public DataExist As Boolean Public Const NoPass = "N0p455w" Public Const StartData = "°|" Public Const StartPass = "|°" Public Const EndData = "DNE"
Public Function Del_Spaces(Str As String) As String On Error GoTo q
Dim Str1 As String Dim Str2 As String Str1 = InStr(1, Str, " ") Str2 = Left$(Str, Str1 - 1) Del_Spaces = Str2
Exit Function q:
Del_Spaces = Str End Function
Private Function Get_Strings(Str As String) As String Dim No_S As String
Dim Get_D As String No_S = Del_Spaces(Str) Get_D = Decrypt(No_S) Get_Strings = Get_D End Function
Public Function Encrypt(ByVal Str As String)
Dim Letter As String, i '---
For i = 1 To Len(Str) ' Very lame type of encryption,.. Letter = Mid$(Str, i, 1) ' I just put it to make an example Mid$(Str, i, 1) = Chr(Asc(Letter) + 10) ' the 10 is the ascii value changed from password...
Next i ' you can change it to what ever you want as long as it's under 255
'this function is the decryption
Public Function Decrypt(ByVal Str As String) Dim Letter As String, i
For i = 1 To Len(Str) Letter = Mid$(Str, i, 1)
Mid$(Str, i, 1) = Chr(Asc(Letter) - 10) Next i
Decrypt = Str End Function
Public Function Check_data(sFIle As String) As Boolean '---
Dim endD As String * 3 ' Function that check if there's data in thefile
Open sFIle For Binary As #1 ' finding the public constant "DNE"
Get #1, LOF(1) - 2, endD '--- Close #1
If endD = EndData Then Check_data = True Else Check_data = False End Function
Public Sub Del_Data(Question As Boolean)
On Error GoTo q '--- Dim Str1 As String ' This Sub delete the data from the file
Dim Str2 As String, StndBy As String '--- Dim box, Instead As String, NewF As String
DataExist = Check_data(nFile) If DataExist = True Then
If Question = False Then GoTo W
box = MsgBox("Are You Sure You Want to Delete ALL The Data In The Current File?", vbCritical + vbYesNo, "Are You Sure?")
If box = vbNo Then Exit Sub Else
W:
Open nFile For Binary As #1 ' Opens the file in binary mode,
AllFile = Space(LOF(1)) ' Grabs ALL the file into the AllFile variable
Get #1, , AllFile Close #1
Str1 = InStrRev(AllFile, StartData, -1) ' Finds the char "°|" in the file
StndBy = InStrRev(AllFile, Str2, -1, vbBinaryCompare) ' Gets the Len of the data, including all tthe strings
Instead = Left$(AllFile, StndBy - 1) ' Gets the file inself, without the data
'---
NewF = App.Path & "\TempFile.SCD"
Open NewF For Binary As #2 '---
Put #2, , Instead ' Creates a new temporary
Close #2 ' file without the data
'---
Kill nFile: Name NewF As nFile ' Delete the current file and renames the Temp one as the normal file
End If Else
MsgBox "This File Does Not Contain Any Data", vbInformation, "Info:..." End If
Exit Sub q:
MsgBox "Error: " & Err.Description, vbInformation, "ERROR:..." End Sub
Function Load_Data(sFIle As String, sPass As String) As String On Error GoTo W
Dim InputPass, FornE As String * 3
Dim ForN As String * 5, ForP As String * 2 Dim Str1 As String, New_data As String Dim Passw As String, Datan As String
DataExist = Check_data(sFIle)
If DataExist = False Then
MsgBox "This File Does Not Contain Any Data", vbInformation, "Info:..." Else
If FileLen(sFIle) >= 64000 Then MsgBox "Tekan Tombol oke ", vbInformation, "INFO:..."
DoEvents Close #1
TxtLen = Get_Strings(ForN) PassLen = Get_Strings(ForP)
Str1 = InStrRev(AllFile, StartPass, -1) New_data = Mid$(AllFile, Str1 + 2) Passw = Left$(New_data, PassLen)
If Passw = NoPass Then ' If the file has no password then...
GoTo q Else
Passw = Decrypt(Left$(New_data, PassLen)) ' Decrypts the password...
'--- InputPass = sPass
If InputPass = Passw Then GoTo q Else MsgBox "Incorrect Password", vbInformation, "ERROR..."
End If
End If Exit Function
q: '---
Str1 = InStrRev(AllFile, StartData, -1) ' Finds the char "°|" in the file New_data = Mid$(AllFile, Str1 + 2) ' Finds the Data encrypted in the file
Datan = Decrypt(Left$(New_data, TxtLen)) ' Decrypts the Data & put it to the textbox
Load_Data = Datan '--- Exit Function
W:
MsgBox "Error: " & Err.Description, vbCritical, "ERROR:..."
End Function
Public Sub Save_Data(sFIle As String, sText As String, nPass As String)
On Error GoTo q '--- Dim Data As String, Passw As String ' This one saves the data in the file :D Dim box '--- DataExist = Check_data(nFile)
If DataExist = True Then
box = MsgBox("There's Currently Data In The File, Do You Want To Overwrite It?", vbInformation + vbYesNo, "Info:..")
Else
Exit Sub End If Else W:
Data = Encrypt(sText)
TxtLen = Encrypt(Len(sText))
' The next commands just put the settings with the data at the END of the file Open sFIle For Binary As #1
Seek #1, LOF(1) + 1 Put #1, , StartData Put #1, , Data Put #1, , StartPass
' If .Check1.Value = vbUnchecked Then
' PassLen = Encrypt("7") ' Encrypt the length of the public const "Nopass" ' Put #1, , NoPass
' Else
Passw = Encrypt(nPass)
PassLen = Encrypt(Len(nPass)) Put #1, , Passw
' End If Put #1, , TxtLen Put #1, , PassLen Put #1, , EndData Close #1
MsgBox "Data Saved Successfully", vbInformation, "Info" End If
Exit Sub q:
MsgBox "Error: " & Err.Description, vbInformation, "ERROR:..." End Sub