Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
- (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
- Private Declare Function ReleaseCapture Lib "user32" () As Long
- Const WM_NCLBUTTONDOWN = &HA1
- Const HTCAPTION = 2
- 'Dim Key As Integer 'пометка ключ
- Dim mainpath, mainpath1 As String
- Dim fnikki As Integer
- 'Private Sub Command1_Click()
- 'Dim MyLine As String
- 'Open mainpath For Input As #1
- ' Do While Not EOF(1)
- ' Line Input #1, MyLine
- ' deb.Text = MyLine
- ' txtput.Text = MyLine
- ' Loop
- 'Close #1
- 'txtput.Text = Decrypt(txtput.Text, 15)
- 'txtput.Text = Decrypt(txtput.Text, kkey.Text)
- 'End Sub
- Private Sub Command2_Click()
- txtput.Text = txtput.Text & vbCrLf & "[" & Time & " " & Date & "]"
- End Sub
- Private Sub Command3_Click()
- End
- End Sub
- Private Sub Form_Load()
- 'Debug.Print "copy " & App.Path & "\nikki.txt " & App.Path & "\backup_nikki.txt"
- mainpath = App.Path & "/nikki.txt"
- mainpath1 = App.Path
- 'FileCopy App.Path & "\nikki.txt", App.Path & "\backup_nikki.txt"
- Close #fnikki
- 'Key = 15 '
- End Sub
- Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
- Call ReleaseCapture
- Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
- End Sub
- Private Sub wr_Click()
- 'Dim cry As String
- 'cry = txtput.Text
- Dim oTest As CRijndael
- Dim sTemp As String
- Dim bytIn() As Byte
- Dim bytOut() As Byte
- Dim bytPassword() As Byte
- Dim bytClear() As Byte
- Dim lCount As Long
- Dim lLength As Long
- Set oTest = New CRijndael
- ' Do a quick and dirty conversion of message and password to byte arrays, as the
- ' string is Unicode we will get two bytes per character. You might want to loop through
- ' instead if you are only dealing in ASCII using the ASC() function so you get one
- ' byte per character.
- ' NOTE: You need to be very careful here if you are encrypting on a system
- ' with one character set and then expecting to decrypt on a different system
- ' with a different character set (e.g. Japanese to US English). It will not be
- ' a problem if you are only using the ASCII range 0-127, but remember, we are
- ' encrypting/decrypting bytes not characters, the byte encryption/decryption
- ' will be correct, but your conversion between bytes and characters needs to be
- ' tested out.
- bytIn = txtput.Text
- bytPassword = kkey.Text
- ' This is the alternate way for single bytes...
- ' sTemp = txtPlain.Text
- ' lLength = Len(sTemp)
- ' ReDim bytIn(lLength - 1)
- ' For lCount = 1 To lLength
- ' bytIn(lCount - 1) = AscB(Mid(sTemp, lCount, 1))
- ' Next
- ' sTemp = txtKey.Text
- ' lLength = Len(sTemp)
- ' ReDim bytPassword(lLength - 1)
- ' For lCount = 1 To lLength
- ' bytPassword(lCount - 1) = AscB(Mid(sTemp, lCount, 1))
- ' Next
- ' Encrypt the data
- bytOut = oTest.EncryptData(bytIn, bytPassword)
- Dim fnikki As Integer
- fnikki = FreeFile
- Open mainpath For Binary As #fnikki
- 'put0 = Encrypt(txtput.Text, 15)
- Put #fnikki, , bytOut
- Close #fnikki
- End Sub
- Private Sub rd_Click()
- Dim oTest As CRijndael
- Dim sTemp As String
- Dim bytIn() As Byte
- Dim bytOut() As Byte
- Dim bytPassword() As Byte
- Dim bytClear() As Byte
- Dim lCount As Long
- Dim lLength As Long
- Set oTest = New CRijndael
- Dim bData() As Byte
- Open mainpath For Binary As #1
- If LOF(1) > 0 Then
- ' Decrypt
- ReDim bData(LOF(1) - 1)
- Get #1, , bData()
- bytClear = oTest.DecryptData(bData(), kkey.Text)
- ' Quick and dirty conversion back to a string. If we earlier looped using the ASC() function
- ' to get one byte per character, we will now need to do the opposite and loop using
- ' the CHR() function to put the string back together again.
- 'txtPlainAgain.Text = bytClear
- txtput.Text = bytClear
- ' This is the alternate way for single bytes...
- ' lLength = UBound(bytClear) + 1
- ' sTemp = String(lLength, " ")
- ' For lCount = 1 To lLength
- ' Mid(sTemp, lCount, 1) = Chr(bytClear(lCount - 1))
- ' Next
- ' txtPlainAgain.Text = sTemp
- deb.Text = "*** DEBUG" & vbCrLf & txtput.Text
- End If
- Close #1
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement