refined crypto function