I am an undergraduate working as a research assistant for a university, primarily alongside a supervisor. While I have my own project, my job still has me assisting my supervisor in his main research. 

Recently, my supervisor assigned me a small coding project that would expedite data analysis for experiments, benefiting both of us. I would gladly write code that simplifies his work and mine as is my job as his assistant. However, I am anxious that the code I have written will be dispersed and used throughout the research group. This sentiment is due to the fact that this coding project arose during group conversation including myself, my supervisor and another researcher, who pointed out such a program would save himself and others in the department time and energy.

**My Two Questions**

Am I justified in feeling like I'm being exploited by the other researcher to write this code or am I being selfish? 

Can I protect my code from others using it without creating tension/enemies?

I believe my energy and time are first and foremost reserved for my supervisor's work and my own. This is code that is relatively easy to write but is rather time intensive. I see that if the other researcher wants to have this shortcut in data analysis, he could write it himself. It wouldn't bother me as much if the project came directly from my supervisor as it would be explicitly for us. Afterward if it were shared, I don't think I would be as conflicted. Rather, the researcher who pushed the project is far removed from my work.

Otherwise, if this code does spread to other researchers, how would I ensure I receive recognition for it? I am pursuing further education with this department and want to better my reputation to admissions as a meaningful member of the research group. Perhaps I am being too petty or selfish with the impact of this code. This is the first time I've experienced writing code for something beyond classwork and I would like to approach the situation the right way.

**Edit**

Thanks all for showing me I was being really, truly idiotic. Most of these comments make sense or doled out the slap up the head I needed. Being able to better other industries is a huge point of my interest in the field so seeing it from the outside made it obvious I was being a hypocrite. I realize I need to change my mindset if research is something I want to pursue in the future. In the meantime, I'll diversify the code as much as possible to help as many as I can. Thanks all for the input.