Hi, sorry for the late response. It's been a looong time since I did anything with my arduino, really, but I will try to answer your questions.
-
I am actually pretty inexperienced programming the arduino myself; however I have some programming background in other languages so I don't really know what is going on in there, but if I remember correctly I used that because the first 10 characters of keycode were correct, but then after that it just gave me garbage, so I just extracted the first 10 digits. There should be a more elegant way to solve this problem, but I just did it like that.
-
Again, this can probably be written more elegantly, but just Interpret that statement like this
if (you swipe the master key AND you are not in programming mode) [note both statements have to be true. NOT just one]
enter programming mode and turn on the programming mode light [so the user knows we are in programming mode]
else [note that at this point you can be in programming mode if the key you swiped previously was the master]
if( you are NOT in programming mode)