hack that key validation.


P

pawel667

I've got a homework to do for a next week, and cannot pass it.
I had to create key which pass the validation for name
"sample.domain.com".
Any idea to simple reverse it ?

Here is a code:
########################


Imports System
Imports System.Collections
Imports System.Net
Imports System.Text


Namespace WebCon.WebParts.ColorCalendar
Friend Class CodeValidate
' Methods
Public Sub New(ByVal code As String)
Me.key = code
End Sub


Private Function CheckDate(ByVal data As String, ByVal s_sign
As Char) As Boolean
Dim str As String = ""
Dim flag As Boolean = False
data = Me.ConvertIc_Replace(data)
Dim bytes As Byte() = Encoding.ASCII.GetBytes(data)
Dim przesuwacz As Integer = s_sign
Dim i As Integer
For i = 0 To 4 - 1
Dim str2 As String =
Convert.ToString(Me.GetModulo(Convert.ToChar(bytes(i)), przesuwacz))
If (str2 = "15") Then
Me.isTrial = False
flag = False
Exit For
End If
Select Case i
Case 0
If (str2 = "-1") Then
flag = True
goto Label_011F
End If
If (str2.Length >= 2) Then
str = (str & "20" & str2 & "-")
Else
str = (str & "200" & str2 & "-")
End If
Exit Select
Case 1
If (str2 = "-1") Then
flag = True
goto Label_011F
End If
If (str2.Length >= 2) Then
str = (str & str2 & "-")
Else
str = (str & "0" & str2 & "-")
End If
Exit Select
End Select
If (i > 1) Then
If (str2 = "-1") Then
flag = True
Exit For
End If
str = (str & str2)
End If
Next i
Label_011F:
If (Me.isTrial AndAlso Not flag) Then
Me.trialTime = Convert.ToDateTime(str)
End If
Return flag
End Function


Private Function CheckMiszung(ByVal kodProduktu As String,
ByVal domena As String, ByVal stala As String, ByVal key As String,
ByVal s_sign As Char) As Boolean
Dim flag As Boolean = False
domena = (domena & Convert.ToString(s_sign))
stala = (stala & Convert.ToString(s_sign))
kodProduktu = (kodProduktu & Convert.ToString(s_sign))
Dim replaceKey As String = New Md5((domena & stala &
kodProduktu)).getMd5
replaceKey = Me.ic_Replace(replaceKey).Substring(10, 3)
If ((Convert.ToChar(Encoding.ASCII.GetBytes(key)
(0)).ToString & replaceKey.ToUpper) = key) Then
flag = True
End If
Return flag
End Function


Private Function CompareMd5Modules(ByVal group As String,
ByVal stringToMd5 As String, ByVal s_sign As Char, ByVal lastModule
As
Boolean) As Boolean
stringToMd5 = (stringToMd5 & Convert.ToString(s_sign))
Dim replaceKey As String = New Md5(stringToMd5).getMd5
replaceKey = Me.ic_Replace(replaceKey)
If Not lastModule Then
replaceKey = replaceKey.Substring(1, 4)
Else
replaceKey = (replaceKey.Substring(1, 3) &
Convert.ToString(s_sign))
End If
Return (group = replaceKey)
End Function


Private Function ConvertIc_Replace(ByVal replaceKey As
String)
As String
replaceKey = replaceKey.Replace("Z", "0")
replaceKey = replaceKey.Replace("K", "1")
replaceKey = replaceKey.Replace("T", "6")
Return replaceKey.ToUpper
End Function


Private Function CreateKey(ByVal ch As Char, ByVal domena As
String, ByVal stala As String, ByVal kodProduktu As String, ByVal
group As String()) As Boolean
Dim flag As Boolean = True
If Not Me.ValidateDomainName(group(1), ch) Then
Me.ErrorCode = String.Format("Invalid domain name.
{0}, {1}", domena, Me.key)
Return False
End If
If Not Me.CompareMd5Modules(group(2), kodProduktu, ch,
False) Then
Me.ErrorCode = String.Format("Invalid product code.
{0}, {1}", Me.validateDomainName, Me.key)
Return False
End If
If Not Me.CompareMd5Modules(group(4), stala, ch, True)
Then
Me.ErrorCode = String.Format("Invalid special
character. {0}, {1}", Me.validateDomainName, Me.key)
Return False
End If
If Me.CheckDate(group(3), ch) Then
Me.ErrorCode = String.Format("Invalid date. {0},
{1}",
Me.validateDomainName, Me.key)
Return False
End If
If Me.isTrial Then
Dim trialTime As DateTime = Me.trialTime
Dim span As TimeSpan = DirectCast((DateTime.Today -
trialTime), TimeSpan)
If (span.Days > 0) Then
Me.ErrorCode = String.Format("Your trial version
has expired {0} days ago, to buy full version", span.Days)
Return False
End If
Return flag
End If
If Not Me.CheckMiszung(kodProduktu,
Me.validateDomainName,
"COMPANYNAME", group(3), ch) Then
Me.ErrorCode = String.Format("Invalid special
characters. {0}, {1}", domena, Me.key)
Return False
End If
Return flag
End Function


Private Function GetDomainName() As String
Return Dns.GetHostEntry("LocalHost").HostName
End Function


Private Function GetModulo(ByVal [mod] As Char, ByVal
przesuwacz As Integer) As Integer
Dim num As Integer = Convert.ToInt32([mod].ToString,
&H10)
Dim chArray As Char() = New Char() { "0"c, "1"c, "2"c,
"3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c,
"E"c, "F"c }
Dim i As Integer
For i = 0 To &H10 - 1
Dim newAsciiNumber As Integer =
Me.GetNewAsciiNumber(chArray(i))
If (newAsciiNumber = -1) Then
newAsciiNumber = chArray(i)
End If
If (((newAsciiNumber + przesuwacz) Mod &H10) = num)
Then
Return i
End If
Next i
Return -1
End Function


Private Function GetNewAsciiNumber(ByVal ascii As Char) As
Integer
Select Case ascii
Case "A"c
Return &H3A
Case "B"c
Return &H3B
Case "C"c
Return 60
Case "D"c
Return &H3D
Case "E"c
Return &H3E
Case "F"c
Return &H3F
End Select
Return -1
End Function


Private Function ic_Replace(ByVal replaceKey As String) As
String
replaceKey = replaceKey.Replace("0", "Z")
replaceKey = replaceKey.Replace("1", "K")
replaceKey = replaceKey.Replace("6", "T")
Dim userDomainName As String = Environment.UserDomainName
Return replaceKey.ToUpper
End Function


Public Function IsKeyValidated() As Boolean
Dim flag As Boolean = True
Try
Me.groupKey(0) = Me.key.Split(New Char() { "-"c })(0)
Me.groupKey(1) = Me.key.Split(New Char() { "-"c })(1)
Me.groupKey(2) = Me.key.Split(New Char() { "-"c })(2)
Me.groupKey(3) = Me.key.Split(New Char() { "-"c })(3)
Me.groupKey(4) = Me.key.Split(New Char() { "-"c })(4)
Me.key = Me.key.Replace("-", "")
Catch exception As Exception
Me.ErrorCode = (exception.Message & " " &
exception.StackTrace)
Return False
End Try
Dim bytes As Byte() = Encoding.ASCII.GetBytes(Me.key)
Dim domena As String = Me.GetDomainName.ToUpper
Dim stala As String = "COMPANYNAME"
Dim kodProduktu As String = "PRODUKT_NAME"
If Not Me.CreateKey(Convert.ToChar(bytes(&H13)), domena,
stala, kodProduktu, Me.groupKey) Then
flag = False
End If
Return flag
End Function


Private Function ValidateDomainName(ByVal group As String,
ByVal ch As Char) As Boolean
Dim flag As Boolean = False
Dim domainName As String = Me.GetDomainName
New ArrayList
If (domainName.Split(New Char() { "."c }).Length > 0)
Then
Dim index As Integer = domainName.IndexOf(".")
domainName = domainName.Remove(0, (index + 1))
End If
flag = Me.CompareMd5Modules(group, domainName.ToUpper,
ch,
False)
Me.validateDomainName = domainName.ToUpper
Return (flag OrElse flag)
End Function


' Properties
Public Property ErrorCode As String
Get
Return Me.errorCode
End Get
Set(ByVal value As String)
Me.errorCode = value
End Set
End Property


' Fields
Private errorCode As String
Private groupKey As String() = New String(5 - 1) {}
Private isTrial As Boolean = True
Private key As String
Private trialTime As DateTime
Private validateDomainName As String
End Class
End Namespace


####################################
END CODE
 
Ad

Advertisements

P

Pawel Do Dupy

Pawel do dupy

Spierdalaj ty chuju - odpierdol sie




I've got a homework to do for a next week, and cannot pass it.
I had to create key which pass the validation for name
"sample.domain.com".
Any idea to simple reverse it ?

Here is a code:
########################


Imports System
Imports System.Collections
Imports System.Net
Imports System.Text


Namespace WebCon.WebParts.ColorCalendar
Friend Class CodeValidate
' Methods
Public Sub New(ByVal code As String)
Me.key = code
End Sub


Private Function CheckDate(ByVal data As String, ByVal s_sign
As Char) As Boolean
Dim str As String = ""
Dim flag As Boolean = False
data = Me.ConvertIc_Replace(data)
Dim bytes As Byte() = Encoding.ASCII.GetBytes(data)
Dim przesuwacz As Integer = s_sign
Dim i As Integer
For i = 0 To 4 - 1
Dim str2 As String =
Convert.ToString(Me.GetModulo(Convert.ToChar(bytes(i)), przesuwacz))
If (str2 = "15") Then
Me.isTrial = False
flag = False
Exit For
End If
Select Case i
Case 0
If (str2 = "-1") Then
flag = True
goto Label_011F
End If
If (str2.Length >= 2) Then
str = (str & "20" & str2 & "-")
Else
str = (str & "200" & str2 & "-")
End If
Exit Select
Case 1
If (str2 = "-1") Then
flag = True
goto Label_011F
End If
If (str2.Length >= 2) Then
str = (str & str2 & "-")
Else
str = (str & "0" & str2 & "-")
End If
Exit Select
End Select
If (i > 1) Then
If (str2 = "-1") Then
flag = True
Exit For
End If
str = (str & str2)
End If
Next i
Label_011F:
If (Me.isTrial AndAlso Not flag) Then
Me.trialTime = Convert.ToDateTime(str)
End If
Return flag
End Function


Private Function CheckMiszung(ByVal kodProduktu As String,
ByVal domena As String, ByVal stala As String, ByVal key As String,
ByVal s_sign As Char) As Boolean
Dim flag As Boolean = False
domena = (domena & Convert.ToString(s_sign))
stala = (stala & Convert.ToString(s_sign))
kodProduktu = (kodProduktu & Convert.ToString(s_sign))
Dim replaceKey As String = New Md5((domena & stala &
kodProduktu)).getMd5
replaceKey = Me.ic_Replace(replaceKey).Substring(10, 3)
If ((Convert.ToChar(Encoding.ASCII.GetBytes(key)
(0)).ToString & replaceKey.ToUpper) = key) Then
flag = True
End If
Return flag
End Function


Private Function CompareMd5Modules(ByVal group As String,
ByVal stringToMd5 As String, ByVal s_sign As Char, ByVal lastModule
As
Boolean) As Boolean
stringToMd5 = (stringToMd5 & Convert.ToString(s_sign))
Dim replaceKey As String = New Md5(stringToMd5).getMd5
replaceKey = Me.ic_Replace(replaceKey)
If Not lastModule Then
replaceKey = replaceKey.Substring(1, 4)
Else
replaceKey = (replaceKey.Substring(1, 3) &
Convert.ToString(s_sign))
End If
Return (group = replaceKey)
End Function


Private Function ConvertIc_Replace(ByVal replaceKey As
String)
As String
replaceKey = replaceKey.Replace("Z", "0")
replaceKey = replaceKey.Replace("K", "1")
replaceKey = replaceKey.Replace("T", "6")
Return replaceKey.ToUpper
End Function


Private Function CreateKey(ByVal ch As Char, ByVal domena As
String, ByVal stala As String, ByVal kodProduktu As String, ByVal
group As String()) As Boolean
Dim flag As Boolean = True
If Not Me.ValidateDomainName(group(1), ch) Then
Me.ErrorCode = String.Format("Invalid domain name.
{0}, {1}", domena, Me.key)
Return False
End If
If Not Me.CompareMd5Modules(group(2), kodProduktu, ch,
False) Then
Me.ErrorCode = String.Format("Invalid product code.
{0}, {1}", Me.validateDomainName, Me.key)
Return False
End If
If Not Me.CompareMd5Modules(group(4), stala, ch, True)
Then
Me.ErrorCode = String.Format("Invalid special
character. {0}, {1}", Me.validateDomainName, Me.key)
Return False
End If
If Me.CheckDate(group(3), ch) Then
Me.ErrorCode = String.Format("Invalid date. {0},
{1}",
Me.validateDomainName, Me.key)
Return False
End If
If Me.isTrial Then
Dim trialTime As DateTime = Me.trialTime
Dim span As TimeSpan = DirectCast((DateTime.Today -
trialTime), TimeSpan)
If (span.Days > 0) Then
Me.ErrorCode = String.Format("Your trial version
has expired {0} days ago, to buy full version", span.Days)
Return False
End If
Return flag
End If
If Not Me.CheckMiszung(kodProduktu,
Me.validateDomainName,
"COMPANYNAME", group(3), ch) Then
Me.ErrorCode = String.Format("Invalid special
characters. {0}, {1}", domena, Me.key)
Return False
End If
Return flag
End Function


Private Function GetDomainName() As String
Return Dns.GetHostEntry("LocalHost").HostName
End Function


Private Function GetModulo(ByVal [mod] As Char, ByVal
przesuwacz As Integer) As Integer
Dim num As Integer = Convert.ToInt32([mod].ToString,
&H10)
Dim chArray As Char() = New Char() { "0"c, "1"c, "2"c,
"3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c,
"E"c, "F"c }
Dim i As Integer
For i = 0 To &H10 - 1
Dim newAsciiNumber As Integer =
Me.GetNewAsciiNumber(chArray(i))
If (newAsciiNumber = -1) Then
newAsciiNumber = chArray(i)
End If
If (((newAsciiNumber + przesuwacz) Mod &H10) = num)
Then
Return i
End If
Next i
Return -1
End Function


Private Function GetNewAsciiNumber(ByVal ascii As Char) As
Integer
Select Case ascii
Case "A"c
Return &H3A
Case "B"c
Return &H3B
Case "C"c
Return 60
Case "D"c
Return &H3D
Case "E"c
Return &H3E
Case "F"c
Return &H3F
End Select
Return -1
End Function


Private Function ic_Replace(ByVal replaceKey As String) As
String
replaceKey = replaceKey.Replace("0", "Z")
replaceKey = replaceKey.Replace("1", "K")
replaceKey = replaceKey.Replace("6", "T")
Dim userDomainName As String = Environment.UserDomainName
Return replaceKey.ToUpper
End Function


Public Function IsKeyValidated() As Boolean
Dim flag As Boolean = True
Try
Me.groupKey(0) = Me.key.Split(New Char() { "-"c })(0)
Me.groupKey(1) = Me.key.Split(New Char() { "-"c })(1)
Me.groupKey(2) = Me.key.Split(New Char() { "-"c })(2)
Me.groupKey(3) = Me.key.Split(New Char() { "-"c })(3)
Me.groupKey(4) = Me.key.Split(New Char() { "-"c })(4)
Me.key = Me.key.Replace("-", "")
Catch exception As Exception
Me.ErrorCode = (exception.Message & " " &
exception.StackTrace)
Return False
End Try
Dim bytes As Byte() = Encoding.ASCII.GetBytes(Me.key)
Dim domena As String = Me.GetDomainName.ToUpper
Dim stala As String = "COMPANYNAME"
Dim kodProduktu As String = "PRODUKT_NAME"
If Not Me.CreateKey(Convert.ToChar(bytes(&H13)), domena,
stala, kodProduktu, Me.groupKey) Then
flag = False
End If
Return flag
End Function


Private Function ValidateDomainName(ByVal group As String,
ByVal ch As Char) As Boolean
Dim flag As Boolean = False
Dim domainName As String = Me.GetDomainName
New ArrayList
If (domainName.Split(New Char() { "."c }).Length > 0)
Then
Dim index As Integer = domainName.IndexOf(".")
domainName = domainName.Remove(0, (index + 1))
End If
flag = Me.CompareMd5Modules(group, domainName.ToUpper,
ch,
False)
Me.validateDomainName = domainName.ToUpper
Return (flag OrElse flag)
End Function


' Properties
Public Property ErrorCode As String
Get
Return Me.errorCode
End Get
Set(ByVal value As String)
Me.errorCode = value
End Set
End Property


' Fields
Private errorCode As String
Private groupKey As String() = New String(5 - 1) {}
Private isTrial As Boolean = True
Private key As String
Private trialTime As DateTime
Private validateDomainName As String
End Class
End Namespace


####################################
END CODE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top