solve hw4

could be more efficient and secure