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- A. uvw
- B. abc
- C. {|}
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The number of distinct arrangements (permutations of the letters, with identical letters not counted twice) of the string "AABBC" is…
- The string "Programming Language" is taken in lowercase and the procedure below counts its vowels (a, e, i, o, u). What is printed? count…
- For the bracket string "(()(()))", the procedure below tracks the nesting depth and prints the maximum depth reached. What is printed?…
- Longest common prefix of the words "flower", "flow" and "flight" is found by comparing characters column by column until a mismatch. The…
- The words of "the sky is blue" are reversed in order (the words themselves are kept). The procedure below does this and prints the result…
- The string "bananana" is searched for "ana" with overlapping occurrences allowed. The procedure below counts the start positions of…