The emergence and evolution of social norms: Rational cooperation in a finitely repeated prisoners' dilemma