Added a function to replace all the ugly sprintf-ing everywhere

Also used it to get rid of padding-bug in GenerateSID()