Your trend of
questioning and research into your program's implementation does overlap the blackhat domain,
at a quick glance.
It's fine to continue asking, but next time, it would be good to state your intentions like you did
here to avoid further (superficial) suspicions. Besides, stating your intentions also help you more in that other monks can suggest better solutions to your actual
main problem.
With that said, there's lots of third-party tools that already do what you want to do. Search the web. Why not leverage them? If you're writing it for your own education, then it's best to say so, so that other monks can decide whether to help, given that more info is provided.