def mask(buf, key):
 key = [ord(i) for i in key]
 buf = list(buf)
 for (i, char) in enumerate(buf):
  buf[i] = chr((ord(char) ^ key[(i % 4)]))
 return ''.join(buf)

def mask ( buf , key ) : key = [ ord ( i ) for i in key ] buf = list ( buf ) for ( i , char ) in enumerate ( buf ) : buf [ i ] = chr ( ( ord ( char ) ^ key [ ( i % 4 ) ] ) ) return '' . join ( buf )
mask or unmask a buffer of bytes with a masking key .