#NEWLINE# def tds7_crypt_pass( password ) : #NEWLINE# #INDENT# ' Mangle password according to tds rules\n\n    :param password: Password str\n    :returns: Byte-string with encoded password\n    ' #NEWLINE# encoded = bytearray ( ucs2_codec . encode ( password ) [ 0 ] ) #NEWLINE# for ( i , ch ) in enumerate ( encoded ) : #NEWLINE# #INDENT# encoded [ i ] = ( ( ( ( encoded << 4 ) & 255 ) | ( ch >> 4 ) ) ^ 165 ) #NEWLINE# #UNINDENT# return encoded