#!/usr/bin/env sage -python # # RotationCipher: simple shift cipher (aka Caesar cipher) # # This accepts a string s and an integer r, and returns s with each # alphabetic character replaced with the one appearing r letters later. # # Stephen Forrest, http://wandership.ca/ def RotationCipher(s,r): result = [] for x in s: c = ord(x) if c >= 97 and c <= 122: d = chr( ((c-97+r) % 26) + 97 ) elif c >= 65 and c <= 90: d = chr( ((c-65+r) % 26) + 65 ) else: d = x result.append(d) return "".join(result) print RotationCipher("Gaius Julius Caesar", 8)