fix encrypt codes, and add testing scripts