Status regarding co-authorship for a computer science research paper
To answer your questions:

Based on what you say, it does sound like you were treated unfairly.

Leaving you out from the paper given the circumstances is at least unethical. I don't know about legal.

Your collaborators don't sound like nice people. Unfortunately, this is not uncommon in academia, where abuse of junior people is certainly not uncommon, though for obvious reasons statistics are hard to come by.

An obvious option is to write to the journal's editor explaining the situation. If you have contributed significantly to the paper, you certainly have a claim to be considered a co-author. Obviously, make sure you have documentation backing up your claim. If you don't, it is just your word against theirs, and you will quite likely get nowhere. If you have good documentation, it will be more difficult for the journal to ignore your claims, though it is obviously hard to predict what people will do. Given that you were on the first submission attempt, I think that first submission should count as part of the documentation, and should really help your case if you appeal to the journal. It would be easy enough to compare the two versions of the paper. In the first submission, is your contribution described? Also, were the two submissions to different journals?

It is not completely clear from your posting whether the paper has been officially published. If it has, it may be too late to add your name to the list of authors.

Bear in mind that your collaborators will quite possibly try to find a way to get back at you, for any number of reasons. People who behave in the way you described can get extremely petty and unpleasant when they perceive you as "going against them". They also have a remarkable capacity for not taking responsibility for their own actions, and in their own minds will find a way to blame you for the situation. This is not meant to discourage you from standing up for your rights, but just pointing out the reality of the situation.

Personally, I think people should stand up for their rights, but at the end of the day it is your decision.