skpy/conn.py
def getMac256Hash(challenge, appId="msmsgs@msnmsgr.com", key="Q1P7W2E4J9R8U3S5"):
        """
        Generate the lock-and-key response, needed to acquire registration tokens.
        """
        clearText = challenge + appId
        clearText += "0" * (8 - len(clearText) % 8)

        def int32ToHexString(n):
            hexChars = "0123456789abcdef"
            hexString = ""
            for i in range(4):
                hexString += hexChars[(n >> (i * 8 + 4)) & 15]
                hexString += hexChars[(n >> (i * 8)) & 15]
            return hexString

        def int64Xor(a, b):
            sA = "{0:b}".format(a)
            sB = "{0:b}".format(b)
            sC = ""
            sD = ""
            diff = abs(len(sA) - len(sB))
            for i in range(diff):
                sD += "0"
            if len(sA) < len(sB):
                sD += sA
                sA = sD
            elif len(sB) < len(sA):
                sD += sB
                sB = sD
            for i in range(len(sA)):
                sC += "0" if sA[i] == sB[i] else "1"
            return int(sC, 2)

        def cS64(pdwData, pInHash):
            MODULUS = 2147483647
            CS64_a = pInHash[0] & MODULUS
            CS64_b = pInHash[1] & MODULUS
            CS64_c = pInHash[2] & MODULUS
            CS64_d = pInHash[3] & MODULUS
            CS64_e = 242854337
            pos = 0
            qwDatum = 0
            qwMAC = 0
            qwSum = 0
            for i in range(len(pdwData) // 2):
                qwDatum = int(pdwData[pos])
                pos += 1
                qwDatum *= CS64_e
                qwDatum = qwDatum % MODULUS
                qwMAC += qwDatum
                qwMAC *= CS64_a
                qwMAC += CS64_b
                qwMAC = qwMAC % MODULUS
                qwSum += qwMAC
                qwMAC += int(pdwData[pos])
                pos += 1
                qwMAC *= CS64_c
                qwMAC += CS64_d
                qwMAC = qwMAC % MODULUS
                qwSum += qwMAC
            qwMAC += CS64_b
            qwMAC = qwMAC % MODULUS
            qwSum += CS64_d
            qwSum = qwSum % MODULUS
            return [qwMAC, qwSum]

        cchClearText = len(clearText) // 4
        pClearText = []
        for i in range(cchClearText):
            pClearText = pClearText[:i] + [0] + pClearText[i:]
            for pos in range(4):
                pClearText[i] += ord(clearText[4 * i + pos]) * (256 ** pos)
        sha256Hash = [0, 0, 0, 0]
        hash = hashlib.sha256((challenge + key).encode("utf-8")).hexdigest().upper()
        for i in range(len(sha256Hash)):
            sha256Hash[i] = 0
            for pos in range(4):
                dpos = 8 * i + pos * 2
                sha256Hash[i] += int(hash[dpos:dpos + 2], 16) * (256 ** pos)
        macHash = cS64(pClearText, sha256Hash)
        macParts = [macHash[0], macHash[1], macHash[0], macHash[1]]
        return "".join(map(int32ToHexString, map(int64Xor, sha256Hash, macParts)))
def getMac256Hash(challenge, appId="msmsgs@msnmsgr.com", key="Q1P7W2E4J9R8U3S5"):
        """
        Generate the lock-and-key response, needed to acquire registration tokens.
        """
        clearText = challenge + appId
        clearText += "0" * (8 - len(clearText) % 8)

        def int32ToHexString(n):
            hexChars = "0123456789abcdef"
            hexString = ""
            for i in range(4):
                hexString += hexChars[(n >> (i * 8 + 4)) & 15]
                hexString += hexChars[(n >> (i * 8)) & 15]
            return hexString

        def int64Xor(a, b):
            sA = "{0:b}".format(a)
            sB = "{0:b}".format(b)
            sC = ""
            sD = ""
            diff = abs(len(sA) - len(sB))
            for i in range(diff):
                sD += "0"
            if len(sA) < len(sB):
                sD += sA
                sA = sD
            elif len(sB) < len(sA):
                sD += sB
                sB = sD
            for i in range(len(sA)):
                sC += "0" if sA[i] == sB[i] else "1"
            return int(sC, 2)

        def cS64(pdwData, pInHash):
            MODULUS = 2147483647
            CS64_a = pInHash[0] & MODULUS
            CS64_b = pInHash[1] & MODULUS
            CS64_c = pInHash[2] & MODULUS
            CS64_d = pInHash[3] & MODULUS
            CS64_e = 242854337
            pos = 0
            qwDatum = 0
            qwMAC = 0
            qwSum = 0
            for i in range(len(pdwData) // 2):
                qwDatum = int(pdwData[pos])
                pos += 1
                qwDatum *= CS64_e
                qwDatum = qwDatum % MODULUS
                qwMAC += qwDatum
                qwMAC *= CS64_a
                qwMAC += CS64_b
                qwMAC = qwMAC % MODULUS
                qwSum += qwMAC
                qwMAC += int(pdwData[pos])
                pos += 1
                qwMAC *= CS64_c
                qwMAC += CS64_d
                qwMAC = qwMAC % MODULUS
                qwSum += qwMAC
            qwMAC += CS64_b
            qwMAC = qwMAC % MODULUS
            qwSum += CS64_d
            qwSum = qwSum % MODULUS
            return [qwMAC, qwSum]

        cchClearText = len(clearText) // 4
        pClearText = []
        for i in range(cchClearText):
            pClearText = pClearText[:i] + [0] + pClearText[i:]
            for pos in range(4):
                pClearText[i] += ord(clearText[4 * i + pos]) * (256 ** pos)
        sha256Hash = [0, 0, 0, 0]
        hash = hashlib.sha256((challenge + key).encode("utf-8")).hexdigest().upper()
        for i in range(len(sha256Hash)):
            sha256Hash[i] = 0
            for pos in range(4):
                dpos = 8 * i + pos * 2
                sha256Hash[i] += int(hash[dpos:dpos + 2], 16) * (256 ** pos)
        macHash = cS64(pClearText, sha256Hash)
        macParts = [macHash[0], macHash[1], macHash[0], macHash[1]]
        return "".join(map(int32ToHexString, map(int64Xor, sha256Hash, macParts)))
Generate the lock-and-key response, needed to acquire registration tokens.