I would say that the first thing you need to do is pay attention to your compiler warnings, you should be getting several. Never ignore warnings, they are a good sign of problems with your code.
1 2 3 4 5 6 7 8 9 10 11
In function 'std::string encryption(std::string, std::string)':
40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
83:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In function 'std::string keypreprocess(std::string)':
112:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In function 'std::string ptpreprocess(std::string)':
129:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
136:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
145:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In function 'node search(char (*)[5], char)':
29:1: warning: control reaches end of non-void function [-Wreturn-type]
In function search(), if p isn't found there's nothing returned - but the function requires a type node returned. Note there's no need to use struct node for the return type. Just node is OK with C++. This is the main issue reported by the warnings (L29)