def convert(reader): newReader = ByteReader() for i in xrange(len(reader)): value = reader.readByte(True) value = ~(value - i % 256) % 256 newReader.writeByte(value, True) newReader.seek(0) return newReader