Would an obscene contract be enforceable? If an otherwise-legitimate contract was written in a way that its text was obscene under the Miller test would that affect the enforceability of the contract?
You may be mistaken about the purpose of the Miller test. If some content is obscene according to the Miller test, then it does not receive First Amendment protection, and could be prohibited from distribution by the government. However, it says nothing about the contractual obligations that two parties can agree to. To the extent that the obligations themselves are objectionable this analysis would fall under the doctrines of unconscionability and public policy.
The primary question, in case of such a lawsuit, is whether you accepted the terms of the contract. You could accept the terms verbally, or you could accept them with a signature, or you could even accept by behavior (such as showing up to work). If you breach the contract and you want to make the argument that you didn't accept the offer (or some identifiable part of the offer), the plaintiffs would have a "yes you did" piece of paper to support their side. Now you would have to advances a very dangerous claim, that you didn't sign the document and that the signature there is a forgery. This is dangerous, because you perjured yourself in so testifying (it would eventually come down to you testifying, that you didn't sign the document). It's really beyond the scope of Law SE to get into forensic graphanalysis debates, but you should expect that the other side will have compelling expert testimony that you did in fact sign the document, with your other hand. In a civil suit (breach of contract), the other side would have to show that it is most likely that you did agree to the terms. It isn't just about the signature, it's about all of the evidence, which would include eyewitness testimony ("I saw him sign it", "I gave him the pile of papers and he returned them all, signed" or a later conversation "Remember that you agreed to X" – "Yeah, whatever").
That is, you don't even have to give them a copy of the contract. In the same way you might reference some legal code without actually copying the legal code directly into the contract. If you do not communicate material terms of the contract to your contractor, the contract will be unenforceable due to lack of meeting of minds. Referencing "some legal code", provided that that code is publicly available is fine: your contractor can look it up and decide if they are happy with it. But doing the same with "Independent Contractor Agreement #123" will only work if you provide a copy of it to your contractor. For example, it can be attached to the paper being signed as a Schedule. So, in a nut shell, abstracting prose out is fine as long as it is communicated/attached.
A contract that tells one party or another to do an illegal thing is void ab initio: courts will not recognize it or give force to it. A contract which doesnt explicitly tell either party to do something illegal but if during the course of fulfilling either party's end of the bargain they commit an illegal act it is up to the courts discretion what happens, whether to find the contract void or to maintain the contract (its a matter of public policy whether they allow the contract to continue existing, or if the contract was such that illegal acts were expected to be commited then the court will likely remder it void) Either way, you cannot indemnify someone for committing an illegal act.
This would be entirely dependant on the jurisdiction. The things that would need to be legal to make this transaction legal are: Is the sexual act legal? Is gambling legal? Ongoing consent by both parties To make this an enforceable contract, in addition you would need: Sexual acts to be valuable consideration, basically, is prostitution legal? The fundamentals of a binding contract: intention, legality of objects etc.
For a contract (including ToS) to be valid, one of the things it must have is "legality of objects". That is, if the contract purports to require anything that is unlawful in the jurisdiction then (barring a severance clause) it is not a contract. In common law countries, the starting point is that people are free to contract for and about anything they like - a contract is simply a mechanism for exchanging value between the parties on whatever terms they wish. However, judges and legislatures have decided that there are some things you cannot trade and some terms that are unconscionable or against the public interest and these vary from jurisdiction to jurisdiction*. For example, a contract is not legal in any jurisdiction if its terms seek to exclude the intervention of the courts - this is against public policy. So for example, a binding arbitration clause requiring the parties to accept a private arbitrator's decision as final excludes the courts, yes? Well, in Australia, yes, such clauses if used in a contract between parties with different bargaining power (like a Telco and its customers) are invalid because they prevent the weaker party pursuing a class action. However, they are perfectly legal in the United States because the SCOTUS has determined that the customer can persue litigation after arbitration is finished so this doesn't impede the courts. These are essentially the same laws interpreted by the courts so that they have totally opposite effects. So this might lead you to think that you'll put one in - it'll be OK in the US and Australians will represent such a tiny share of your market that you don't care if I can't enforce my ToS there. Except, if your website is visible by Australians, you have just exposed yourself to a government fine of up to AUD 5,000,000 (say USD 3,000,000) per day for breach of Australian Consumer Law. As a general guide (which is very stereotypical), US jurisdictions are the most permissive in the rights they will allow their citizens to give up: the US attitude is that everyone is free to make the best deal they can. European jurisdictions are the least permissive in this regard: most European countries follow a more social welfare state model and the citizen needs protecting from themselves. Commonwealth countries tend to be more in the middle.
Unless there is something special in Pakistani case law on this topic, it would pass the originality requirement. In my opinion, it is actually very well laid out, and it is clearly not just slapping a few tags on plain text. This article does not indicate any particularly high standards for originality in Pakistan.
The contract is almost certainly not valid. The answer you linked references the 2001 Federal Circuit case Fomby-Denson v. Dept of the Army. The court, in its opinion, quoted from the 1948 Supreme Court case Hurd v. Hodge: [t]he power of the federal courts to enforce the terms of private agreements is at all times exercised subject to the restrictions and limitations of the public policy of the United States . . . . Where the enforcement of private agreements would be violative of that policy, it is the obligation of courts to refrain from such exertions of judicial power. It is clear that, in the case you propose, the enforcement of such a contract would go against the public interest. Quoting from the 1972 Supreme Court case Branzburg v. Hayes, the Fomby-Denson decision said: it is obvious that agreements to conceal information relevant to commission of crime have very little to recommend them from the standpoint of public policy. It further notes this clause from the First Restatement of Contracts: [a] bargain in which either a promised performance or the consideration for a promise is concealing or compounding a crime or alleged crime is illegal.