Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Zer0 on September 13, 2006, 03:14 PM

Title: sc encoding keys
Post by: Zer0 on September 13, 2006, 03:14 PM
I have managed to get the keys decoded and all but i cant seem to get them re-encoded if someone would be willing to help me with this that would be great. I am also rather new to VB and still learning so, thx.

Zer0
Title: Re: sc encoding keys
Post by: rabbit on September 13, 2006, 03:44 PM
Reverse the algorithm.
Title: Re: sc encoding keys
Post by: Zer0 on September 13, 2006, 03:50 PM
iv been trying but keep comming up with really weird output as soon as i get back from class ill post the code and see if i cant get it that way

edit: rabbit if ur the same person im thinkn of ur friends wit JTN (or jeff) arnt u?
Title: Re: sc encoding keys
Post by: l2k-Shadow on September 13, 2006, 08:57 PM


' Ported from C to VB by l2k-Shadow

Public Sub EncodeSCKey(ByRef CDKey As String, ByVal PublicValue As Long, ByVal PrivateValue As Long, Optional ByVal ProductValue As Long)
Dim tKey(11) As String, tStr As String, tlng As Long, hashKey As Long, pos As Integer, i As Integer
Dim tProduct As String, tPublic As String, tPrivate As String
    'Assemble values into a string
    If Product = 0 Then Product = 1
    If Len(Product) < 2 Then
        tProduct = CStr("0" & Product)
    Else
        tProduct = CStr(Product)
    End If
    tPublic = CStr(PublicValue)
    While Len(tPublic) < 7
        tPublic = "0" & tPublic
    Wend
    tPrivate = CStr(PrivateValue)
    While Len(tPrivate) < 3
        tPrivate = "0" & tPrivate
    Wend
    CDKey = tProduct & tPublic & tPrivate
    'Fill Array
    For i = 0 To 11
        tKey(i) = Mid$(CDKey, i + 1, 1)
    Next i
    'Final Vaues
    hashKey = &H13AC9741
    For i = 11 To 0 Step -1
        tStr = tKey(i)
        If Asc(tStr) <= 55 Then
            tKey(i) = (((hashKey And &HFF) And 7) Xor tStr)
            hashKey = hashKey \ 8
        ElseIf Asc(tStr) < 65 Then
            tKey(i) = ((i And 1) Xor tStr)
        End If
    Next i
    'Unshuffling
    For i = 7 To &HC2 Step &H11
        tlng = i Mod &HC
        tStr = tKey(tlng)
        tKey(tlng) = tKey(pos)
        tKey(pos) = tStr
        pos = pos + 1
    Next i
    'Calculate check digit
    tlng = 3
    For i = 0 To 11
        tlng = tlng + (tKey(i) Xor (tlng * 2))
    Next i
    CDKey = Join(tKey, vbNullString) & CStr(tlng Mod 10)
End Sub

have fun
Title: Re: sc encoding keys
Post by: Hero on September 16, 2006, 06:32 PM
Or use the search function that god gave to you and find:
http://forum.valhallalegends.com/index.php?topic=14023.0
Title: Re: sc encoding keys
Post by: l2k-Shadow on September 16, 2006, 06:35 PM
Quote from: heRo on September 16, 2006, 06:32 PM
Or use the search function that god gave to you and find:
http://forum.valhallalegends.com/index.php?topic=14023.0

that's d2/w2 he was asking for sc.
Title: Re: sc encoding keys
Post by: Zer0 on September 19, 2006, 11:12 PM
yes i was looking for SC also thank you shadow
Title: Re: sc encoding keys
Post by: Hero on September 19, 2006, 11:19 PM
Quote from: Zer0 on September 19, 2006, 11:12 PM
yes i was looking for SC also thank you shadow
I had a hunch  ;D