implement shift_and alogrithm