An Optimal Security Algorithm Based on Elliptic Curve Cryptography for Securing Wireless Sensor Networks