I'm pretty much done converting this code from VB6 to Python, the only problem is that VB6 used aryKey() as a String and I use aKey() (same purpose) as a list() function in Python.

Here is the whole VB6 function:

Here is the function in Python:Code:Public Function RShift(ByVal pnValue As Long, ByVal pnShift As Long) As Double On Error Resume Next RShift = CDbl(pnValue \ (2 ^ pnShift)) End Function Public Function DecodeStarcraftKey(ByVal sKey As String) As String On Error Resume Next Dim R As Double, n As Double, n2 As Double, v As Double, _ v2 As Double, keyvalue As Double, c1 As Byte, c2 As Byte, c As Byte, _ bValid As Boolean, i As Integer, aryKey(0 To 12) As String For i = 1 To 13 aryKey(i - 1) = Mid$(sKey, i, 1) Next i v = 3 For i = 0 To 11 c = aryKey(i) n = Val(c) n2 = v * 2 n = n Xor n2 v = v + n Next i v = v Mod 10 If Hex(v) = aryKey(12) Then bValid = True End If v = 194 For i = 11 To 0 Step -1 If v < 7 Then GoTo continue c = aryKey(i) n = CInt(v / 12) n2 = v Mod 12 v = v - 17 c2 = aryKey(n2) aryKey(i) = c2 aryKey(n2) = c Next i continue: v2 = &H13AC9741 For i = 11 To 0 Step -1 c = UCase$(aryKey(i)) aryKey(i) = c If Asc(c) <= Asc("7") Then v = v2 c2 = v And &HFF c2 = c2 And 7 c2 = c2 Xor c v = RShift(CLng(v), 3) aryKey(i) = c2 v2 = v ElseIf Asc(c) < 65 Then c2 = CByte(i) c2 = c2 And 1 c2 = c2 Xor c aryKey(i) = c2 End If Next i DecodeStarcraftKey = Join(aryKey, "") Erase aryKey() End Function

When I do (in Python) ''.join(aKey) I receive:Code:def shift(value, shift): a = str(value / 2*2*2) if '.' in a: a = a.replace(a[a.find('.'):], '') a = int(a) return a else: return int(a) def aKey(d): return list(d) def remain(a, b): c = a * b return c - a def starkey(key): is_valid = [False] for i in range(1, 13): aKey(i - 1) = key[i:0] v = 3 for i in range(0, 11) c = aKey(i) n = val(c) n2 = v * 2 n = n ^ n2 v = v + n v = remain(v, 10) if hex(v) == aKey(12): is_valid[0] = True v = 194 for i in range(11, 0, -1): if v < 7: v2 = 0x13AC9741 for i in range(11, 0, -1): c = aKey(i).upper() aKey(i) = c if ord(c) <= ord('7'): v = v2 c2 = v and 0xFF c2 = c2 and 7 c2 = c2 ^ c v = shift(int(v), 3) aKey(i) = c2 v2 = v elif ord(c) < 65: c2 = int(i) c2 = c2 and 1 c2 = c2 ^ c aKey(i) = c2 c = aKey(i) n = int(v/12) n2 = remain(v, 12) v = v - 17 c2 = aKey(n2) aKey(i) = c2 aKey(n2) = c return ''.join(aKey)

If I dump the aKey() function and I just use list(), I receive:Code:>>> ''.join(aKey) Traceback (most recent call last): File "<pyshell#60>", line 1, in ? ''.join(aKey) TypeError: sequence expected, function found

I'm sure there is a better way to fixing this up. Any help is appreciated, whether I messed up on something else in the code or you can help with the main problem, so far.Code:>>> ''.join(list) Traceback (most recent call last): File "<pyshell#67>", line 1, in ? ''.join(list) TypeError: sequence expected, type found

Tweet This+ 1 thisPost To Linkedin