In upholding state laws that require sex offenders to register with the authorities and that send three-time criminals to jail for at least 25 years, the Supreme Court on Wednesday reflected not only its own tough-on-crime leanings but also the powerful legacy of two young girls and their terrible fates.

It has been about a decade since 7-year-old Megan Kanka and 12-year-old Polly Klaas were snatched from suburban families and murdered, to the horror of millions who followed the stories on television. Megan was sexually assaulted and killed by a neighbor who, unknown to her parents, was a convicted sex offender. Polly was abducted from a pajama party and killed by a man who had been paroled halfway through a 16-year sentence for kidnapping, assault and burglary.

Yet the cases' impact on the law was both sudden and enduring. Voters and politicians swore that never again would children be vulnerable to lurking pedophiles or criminals freshly spun through the prison revolving door. Within just two years of the Megan Kanka case, all 50 states and the District had adopted their versions of "Megan's Law" establishing sex-offender registries. In the same period, California's voters and legislators approved the tough "three strikes and you're out" law that the high court upheld on Wednesday, followed by parallel laws in 24 other states.

The justices were loath to undo these measures despite growing concerns in the years since they were swiftly enacted that they might be causing collateral damage to the rights of individuals or, especially in the case of California's three-strikes law, saddling taxpayers with high costs to incarcerate offenders for decades.

In that sense, said Yale Law School professor Akhil Amar, the cases were truly victories for the victims' rights movement, which "is trying to even things up by having victims equally personified with defendants in the very high drama of a judicial proceeding."

"Even if these crimes in these cases are nonviolent, the narrative is one of violent crime against a very innocent victim, a child -- a girl, the most vulnerable person in our society -- and every parent can project himself into that nightmare scenario," Amar said.

In the justices' various opinions, it was evident that -- quite apart from the constitutional issues -- the narratives of these two young girls and other victims had more resonance with most members of the court than did the sagas of those who were protesting the laws' impact on them.

Justice Anthony M. Kennedy's opinion in favor of Alaska's Megan's Law -- one of the nation's toughest in terms of the detailed information it requires offenders to report to authorities for posting on the Internet every three months -- opens with a recitation of the brutal facts of Megan's case.

And Justice Sandra Day O'Connor begins her opinion upholding Gary Ewing's sentence of 25 years to life for stealing $1,197 worth of golf clubs with a summary of the Polly Klaas case, including the observation that, had her killer served his entire previous sentence, "he would still have been in prison on the day that Polly Klaas was kidnaped."

The staying power of the girls' narratives was particularly striking because, in these cases, opponents of the laws also had what they thought were tales of victimization to tell.

In the challenge to Alaska's Megan's Law, one of the sex offenders was a man who had completed his sentence for molesting his daughter beforethe law was passed. He had completed a course of treatment, been declared rehabilitated by a judge and recovered custody of a minor daughter. But only two dissenting justices, Ruth Bader Ginsburg and Stephen G. Breyer, took account of that.

Ewing, the California man convicted of grand theft for shoplifting golf clubs after prior burglary and robbery convictions and sentenced to 25 years to life, now has AIDS and is partially blind. He is serving his term in a prison hospital.

Yet O'Connor characterized Ewing as someone who was paying the price for a lifetime of crime.

In effect, a majority of the court in the three-strikes cases reached a view not too different from that of Polly's father, Marc Klaas, who became a victim's rights activist after his daughter was slain.

Originally opposed to California's three-strikes law because he feared it would hurt too many minor offenders, Klaas believes subsequent modifications have made it acceptable.

"It puts bad boys away, and that's what society needs," he said. "Polly's murder was a clear case of good and evil. They sold three-strikes as a way to deal with it, and they never talked about all the ambiguities in it. I believe those issues have been adequately addressed. . . . I'm sure a couple of guys may have gotten hung up in it who shouldn't have, but no statute is perfect."