You have the same problem as me, although I've had my cat about 5 years now. I got her from the Toronto Humane Society and not long after I got her home she started attacking my feet! Anytime I would pet her she'd purr and enjoy it for a while and then suddenley attack. As for visitors first she will hide, then she will go up to them interested, then stratch or bite them!
Fast forward 5 years and nothing much has changed. Last year my vet suggested putting her on an anti-anxiety medication called Clomipramine. We put her on it for 3 months and she was a lot better. The vet wanted to wean her off to see if the behaviour was corrected or if she'd need to be on it long term, but once off she reverted back to her old behaviour. So I think its something she'll be on for a while. Its so expensive though! Not sure if its something you'd consider or not.
I think with my cat it is that she gets overly stimulated when being petted, and can only take so much. It wouldnt be so bad if she was just a grumpy cat as we could leave to do her own thing, but she initiates affection by jumping up and cuddling, then attacking! She wacked me in the face the other week, and bit my boyfriend. Anyhow I'll see how the medication works again