+def keyword_cipher_alphabet_of(keyword, wrap_alphabet=False):
+ """Find the cipher alphabet given a keyword
+
+ >>> keyword_cipher_alphabet_of('harry')
+ 'harybcdefgijklmnopqstuvwxz'
+ >>> keyword_cipher_alphabet_of('harry', True)
+ 'haryzbcdefgijklmnopqstuvwx'
+ >>> keyword_cipher_alphabet_of('harry', False)
+ 'harybcdefgijklmnopqstuvwxz'
+ """
+ cipher_alphabet = ''
+ if wrap_alphabet:
+ last_keyword_letter = deduplicate(sanitise(keyword))[-1]
+ last_keyword_position = string.ascii_lowercase.find(last_keyword_letter) + 1
+ cipher_alphabet = ''.join(deduplicate(sanitise(keyword) + string.ascii_lowercase[last_keyword_position:] + string.ascii_lowercase))
+ else:
+ cipher_alphabet = ''.join(deduplicate(sanitise(keyword) + string.ascii_lowercase))
+ return cipher_alphabet
+
+
+def keyword_encipher(message, keyword, wrap_alphabet=False):
+ """Enciphers a message with a keyword substitution cipher
+
+ >>> keyword_encipher('test message', 'harry')
+ 'sbqs kbqqhdb'
+ >>> keyword_encipher('test message', 'harry', True)
+ 'qzpq jzpphcz'
+ >>> keyword_encipher('test message', 'harry', False)
+ 'sbqs kbqqhdb'
+ """
+ cipher_alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet)