I know I have struggled with this; it has been a tough fight, but with God’s grace and Our Lady’s intercession I am finally free of it. Though I still struggle with impure thoughts, God has helped me break a habit I never thought I would! It can be done, so hang in there and keep going!
One thing I found that helped me was the Three Hail Mary devotion. It was miraculous, actually; I started praying, and within a few days I had drastically improved. Just say three Hail Marys when you wake up and before you go to sleep. Ask Our Lady to pray for you and protect you from sexual sin, ask Our Lord for His strength, and ask the Holy Spirit to guide you. Saying this every morning and night not only blessed me with abundant grace, but reminded me that God was there with me in my struggles. That is a great comfort.
The devil will try to tempt you; he will try to tell you that you can’t win, or that there is nothing wrong with this sin of impurity. He will get at you in any way he can. Pray to your guardian angel and St. Michael. Always have holy water! Remember, the devil is the ultimate loser, and he won’t win against God. God is on your side and you can fight off temptation!
Also try to say a rosary every day, and pray the Liturgy of the Hours if you have time. Both have given me great peace and helped me avoid sin. (The rosary actually cured my panic attacks!)
I’m sorry I wrote a novel! I will be praying for you! I hope what I wrote helped! God bless you and grant you grace and peace to overcome this sin and follow Him more closely!