I agree that it sounds like your teacher let you know they know, and that you need to come forward. Talk to your parents and go see your teacher as soon as possible. This is a learning opportunity, not the end of your academic journey.
Just be sure to learn from the mistake and not do it again because the consequences at a college level can be much more severe. Something similar happened in a college course my D was working as the course grader. Someone got a hold of a different exam and answered those questions, in that other order, instead of what was on the actual exam. The students who came forward were given zeroes but had time to bring up their grade. Those that didn’t come forward had their names given to the dean and dropped from the class with a failing grade with no ability to re-take (which was a required course for the major). That was also grounds for expulsion but my D didn’t hear about the long term consequences.