correct encrypt flag handling in writePacket