When You started lock script, he will ask for sudo password and will change the owner and permissions of selected folder or file to 700 on root user. Unlock script, after sudo password, change permissions on selected folder/file to 777 on current user. Both of scripts killed sudo session before and after execution. This guaranteed password permissions every time when you or someone else trying to execute script.
First archive contain scripts on english, second is on bulgarian. Enjoy!