maidinhdan > 03-05-20, 11:46 PM
' --------------------------------------------------------------------------------------------------------
' Thuoc Modules/Class: modTaoKhoaPhanMem4
' Ten ham/thu tuc : MaHoaKeyDangky2
' Tao tren may PC : HENDANWIN10PRO
' Author/ Tac gia : maidinhdan@gmail.com
' Ngay tao : 01/05/2020 3:52:53 PM
' Parameters/Tham so : 'KeyDangky: la ma o cung cua ban, no se cat lay 9 ky tu de ma hoa
'MatKhau, ThoihanDungChuongTrinh phai co 6 ky tu va chi chap nhan so
' Cu phap/ Purpose :
' Pham vi ap dung : Thuat toan ma hoa Thuan Nghich
' --------------------------------------------------------------------------------------------------------
Function MaHoaKeyDangky(KeyDangky As String, MatKhau As String, ThoihanDungChuongTrinh As String) As String
Dim b1 As String, b2 As String, b3 As String
Dim i As Byte, n As Byte
MaHoaKeyDangky = ""
n = 9
' Nén từ 12 xuống còn 6 ký tự=> 9+6=15
b1 = Left(KeyDangky, n) & GiaiMaFromHex(Left(MatKhau, 6)) & GiaiMaFromHex(Left(ThoihanDungChuongTrinh, 6))
n = Len(b1)
b2 = GiaiMa(Left(b1, n), 1) ' Ma hoa từ 15 - thanh 30 ky tu
'Tach tung ky tu de ma hoa bac 2 : chia thành 5 cấp mã hóa.
For i = 1 To n
b3 = b3 & MahoaToHex(Mahoa(Mahoa(Mahoa(Mahoa(mID(b2, i, 1), 4), 24), 1), 26))
If i = 3 Or i = 6 Or i = 9 Or i = 12 Then ' Dòng này thêm dấu gạch ngang
b3 = b3 & "-"
End If
Next i
MaHoaKeyDangky = b3
End Function
' Thuoc Modules/Class: modTaoKhoaPhanMem4
' Ten ham/thu tuc : GiaiMaKeyDangky2
' Tao tren may PC : HENDANWIN10PRO
' Author/ Tac gia : maidinhdan@gmail.com
' Ngay tao : 01/05/2020 3:53:47 PM
' Parameters/Tham so : KeyDangkyDaMaHoa: la key sinh ra tu ham MaHoaKeyDangky
' Cu phap/ Purpose :
' Pham vi ap dung : Thuat toan giai ma Thuan Nghich
' --------------------------------------------------------------------------------------------------------
Function GiaiMaKeyDangky(KeyDangkyDaMaHoa As String) As String
Dim b1 As String, b2 As String, b3 As String
Dim i As Byte, n As Byte
b1 = GiaiMaFromHex(Replace(KeyDangkyDaMaHoa, "-", ""))
n = Len(b1)
For i = 1 To n
b2 = b2 & GiaiMa(GiaiMa(GiaiMa(GiaiMa(mID(b1, i, 1), 26), 1), 24), 4)
Next i
b3 = Mahoa(b2, 1)
b3 = Left(b3, 9) & "-" & MahoaToHex(mID(b3, 10, 3)) & "-" & MahoaToHex(Right(b3, 3))
GiaiMaKeyDangky = b3
End Function
' --------------------------------------------------------------------------------------------------------
' Thuoc Modules/Class: modTaoKhoaPhanMem4
' Ten ham/thu tuc : KiemtraKey
' Tao tren may PC : HENDANWIN10PRO
' Author/ Tac gia : maidinhdan@gmail.com
' Ngay tao : 03/05/2020 10:01:46 PM
' Parameters/Tham so :
' Cu phap/ Purpose :
' Pham vi ap dung : Kiem tra khoa con han dung khong
' --------------------------------------------------------------------------------------------------------
Function KiemtraKey(KeyKichHoatTable As String, PassTest As String) As Boolean
On Error GoTo Loi
Dim MatKhau As String, HanDung As String, MaOCung As String, KeyDaGiaiMa As String
Dim HanTest As Date, HanKey As Date
KeyDaGiaiMa = Replace(GiaiMaKeyDangky((KeyKichHoatTable)), "-", "")
MaOCung = Left(KeyDaGiaiMa, 9)
MatKhau = mID(KeyDaGiaiMa, 10, 6)
HanDung = mID(KeyDaGiaiMa, 16, 6)
HanDung = Right(HanDung, 4) & "/" & Val(Left(HanDung, 2)) & "/" & "28"
HanKey = Format(HanDung, "yyyy/mm/dd")
strHamDung = Format(HanKey, "dd/mm/yyyy")
HanTest = Format(Date, "yyyy/mm/dd")
'Test Key kich hoat
If PassTest = MatKhau Then
If MaOCung = Left(DocHDD, 9) Then
If HanKey >= HanTest Then
KiemtraKey = True
' Debug.Print MaOCung, MatKhau, HanDung
End If
End If
End If
Exit Function
Loi:
KiemtraKey = False
End Function
Public strHamDung As String 'Khai bao nay de nay de test hien thi cho cac ban xem thoi
Public Function Mahoa(Data As String, Optional Depth As Integer) As String
Dim TempChar As String, TempAsc As Integer, NewData As String, vChar As Integer
For vChar = 1 To Len(Data)
TempChar = mID$(Data, vChar, 1)
TempAsc = Asc(TempChar)
If Depth = 0 Then Depth = 40
If Depth > 254 Then Depth = 254
TempAsc = TempAsc + Depth
If TempAsc > 255 Then TempAsc = TempAsc - 255
TempChar = Chr(TempAsc)
NewData = NewData & TempChar
Next vChar
Mahoa = NewData
End Function
Public Function GiaiMa(Data As String, Optional Depth As Integer) As String
Dim TempChar As String, TempAsc As Integer, NewData As String, vChar As Integer
For vChar = 1 To Len(Data)
TempChar = mID$(Data, vChar, 1)
TempAsc = Asc(TempChar)
If Depth = 0 Then Depth = 40
If Depth > 254 Then Depth = 254
TempAsc = TempAsc - Depth
If TempAsc < 0 Then TempAsc = TempAsc + 255
TempChar = Chr(TempAsc)
NewData = NewData & TempChar
Next vChar
GiaiMa = NewData
End Function
Function DocHDD()
Dim Disco As Variant, Discos As Variant, abc As String
Set Discos = GetObject("WINMGMTS:").InstancesOf("Win32_PhysicalMedia")
For Each Disco In Discos
abc = Disco.SerialNumber
If Len(Trim(abc)) > 0 Then Exit For
Next
DocHDD = Trim(abc)
End Function
Public Function MahoaToHex(tString As String) As String
Dim i As Integer, S As String
S = ""
For i = 1 To Len(tString)
S = S & Right$("00" & Hex(Asc(mID$(tString, i, 1))), 2)
Next i
MahoaToHex = S
End Function
Function GiaiMaFromHex(strHex As String) As String
Dim lngCount As Long
For lngCount = 1 To Len(strHex) Step 2
GiaiMaFromHex = GiaiMaFromHex & Chr("&h" & mID(strHex, lngCount, 2))
Next
End Function
soluuhuong85 > 04-05-20, 12:32 AM
huuduy.duy > 04-05-20, 08:42 AM
ongke0711 > 04-05-20, 11:53 AM
dotrung > 04-05-20, 12:22 PM
maidinhdan > 04-05-20, 02:43 PM
Trích dẫn:bao.ngquoc@gmail.com>,
soluuhuong85@gmail.com>,
huuduy.duy@gmail.com>
ngày: 13:42, 4 thg 5, 2020
thuyyeu99 > 04-05-20, 03:19 PM
thuyyeu99 > 04-05-20, 08:42 PM