Implementation of cipher function. Bug (0 dowto N) corrected to (0 to N)