3 def rot_string(str, n=13):
4 """Return a rotated version of a string
6 Specifically, this functions returns a version of the input string
7 where each uppercase letter has been advanced 'n' positions in the
8 alphabet (wrapping around). Lowercase letters and any non-alphabetic
9 characters will be unchanged."""
14 result += chr(ord("A") + (ord(letter) - ord("A") + n) % 26)
20 """Return one or more rotated versions of a sring
22 The arg string should be as follows:
24 [count|*] String to be rotated
26 That is, the first word of the string is an optional number (or
27 the character '*'). If this is a number it indicates an amount to
28 rotate each character in the string. If the count is '*' or is not
29 present, then the string will be rotated through all possible 25
32 The result of the rotation is returned as a string (with Slack
35 match = re.match(r'^([0-9]+|\*) (.*)$', args)
38 count = int(match.group(1))
48 reply = "```/rot {} {}\n".format(count if count else '*', text)
51 reply += rot_string(text, count)
53 reply += "\n".join(["{:02d} ".format(count) + rot_string(text, count)
54 for count in range(1, 26)])