Subversion Repositories pytwidcpp

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 scream 1
# -*- coding: utf-8 -*-
2
import sys
3
 
4
def createKey(lock):
5
        """ Function create key from lock for DC connections. """
6
        key = {}
7
        for i in xrange(1, len(lock)):
8
                key[i] = ord(lock[i]) ^ ord(lock[i-1])
9
        key[0] = ord(lock[0]) ^ ord(lock[len(lock)-1]) ^ ord(lock[len(lock)-2]) ^ 5
10
        for i in xrange(0, len(lock)):
11
                key[i] = ((key[i]<<4) & 240) | ((key[i]>>4) & 15)
12
        out = ''
13
        for i in xrange(0, len(lock)):
14
                out += unichr(key[i])
15
        out = out.replace(u'\0', u'/%DCN000%/').replace(u'\5', u'/%DCN005%/').replace(u'\44', u'/%DCN036%/')
16
        out = out.replace(u'\140', u'/%DCN096%/').replace(u'\174', u'/%DCN124%/').replace(u'\176', u'/%DCN126%/')
17
        return out
18