Wireless sensor networks (WSNs) comprise tiny devices known as sensors. These devices are frequently employed in short-range communications and can perform various operations such as monitoring, collecting, analyzing, and processing data. WSNs do not require any infrastructure, are reliable, and can withstand adverse conditions. Sensor networks are autonomous structures in which the sensor nodes can enter or leave the network at any time instant. If the entering node is attacker node it will monitor the network operation and can cause security issues in the network that can affect communication. Existing literature presents security improvements in such networks in the form of cryptography, asymmetric techniques, key distribution, and various protocols. However, these techniques may not be effective in the case of autonomous structures and can increase computational complexity. In this paper, a convolutional technique (CT) is proposed that generates security bits using convolutional codes to prevent malicious node attacks on WSNs. Different security codes are generated at different hops and the simulation results demonstrate that the proposed technique enhances network security and reduces computational complexity compared to existing approaches.