ProgrammingHardInfosys · Cognizant

A Caesar cipher shifts each lowercase letter forward by 3 places, wrapping from z back to a. The procedure below encodes the word "xyz" and prints the result. What is printed?

A Caesar cipher shifts each lowercase letter forward by 3 places, wrapping from z back to a. The procedure below encodes the word "xyz" and prints the result. What is printed?
for each letter c in "xyz"
    output letter ((c - 'a' + 3) mod 26) + 'a'
end for
  1. A. uvw
  2. B. abc
  3. C. {|}
  4. D. bcd

Correct answer: B. abc

Shifting x, y and z forward by 3 with wrap-around gives a, b and c. Shifting backwards gives uvw, skipping the wrap-around gives brace characters, and a shift of 4 gives bcd.

More Pseudocode and Code Tracing questions

Exams that ask this topic