Encode Strings Using a Character Map

This function encodes strings using a simple character map. Letters are mapped to the letter that is 13 positions away in the alphabet, so A becomes N (and N becomes A), B becomes O, and so on. In addition, numbers are mapped to the symbol that occupies the same key on a standard U.S. keyboard, so 1 becomes !, 2 becomes @ (and vice versa), and so on. Other characters are left alone.

The built-in function index(), when called on a string, returns the index in the string of the first occurrence of a substring: It raises a ValueError exception if the substring is not found:

 location = index("hey there", "th") ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.