I heard a shiur recently, that quoted a gemara to the effect that the Jews in Egypt where not immoral. Where is this gemara, or gemeras that talk of this?
תהלים פרק קכב פסוק ד in Rashi. I don't know the Talmudic source offhand.
If all the women were moral, then there would be no one for the men to be immoral with. Egyptian women would not lower themselves be with slaves. Also any children by a man and some other woman would not be a member of the husband's tribe. Thus the certification of Hashem applies to both the men and the women.
4 There ascended the tribes, the tribes of God, testimony to Israel, to give thanks to the name of the Lord.
the tribes of God: Heb. י-ָהּ, which is testimony to Israel, for the heathens were talking about them when they left Egypt, and they would say about them that they were the offspring of adulterous unions. If the Egyptians ruled over their own bodies, surely [they ruled] over their wives. Said the Holy One, blessed be He, “I attest that they are the sons of their fathers.” He bestowed His name upon them: the Reubenites (הראובני), the Simeonites (השמעוני) (Num. 26). He added the letters of the name, one on this side and one on that side. The result is that this name י-ָהּ is testimony to Israel.
אָמַר רַבִּי פִּנְחָס גַּן נָעוּל, אֵלּוּ הַבְּתוּלוֹת. גַּל נָעוּל, אֵלוּ הַבְּעוּלוֹת. מַעְיָן חָתוּם, אֵלּוּ הַזְּכָרִים... אָמַר רַבִּי אַבָּא בַּר כַּהֲנָא, שָׂרָה יָרְדָה לְמִצְרַיִם וְגָדְרָה עַצְמָהּ מִן הָעֶרְוָה, וְכָל הַנָּשִׁים נִגְדְּרוּ בִּזְכוּתָהּ. יוֹסֵף יָרַד לְמִצְרַיִם וְגָדַר עַצְמוֹ מִן הָעֶרְוָה, וְנִגְדְּרוּ כָּל הַזְּכָרִים בִּזְכוּתוֹ.
Rabbi Pinchas says: "A locked garden" refers to the virgins; "a locked spring," to the married women; "a sealed fountain," to the men... Rabbi Abba bar Kahana says: Sarah went down to Egypt and kept herself clear of forbidden relations [when she was abducted by Pharaoh], and all of the women were able to keep clear in her merit; Yosef went down to Egypt and kept himself clear of forbidden relations [with Potiphar's wife], and all of the men were able to keep clear in his merit.