Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keyword). The string is encrypted by taking the keyword, dropping any letters that appear more than once. The rest of the letters of the alphabet that aren't used are then appended to the end of the keyword.

For example, if your string was "hello" and your keyword was "wednesday", your encryption key would be 'wednsaybcfghijklmopqrtuvxz'.

To encrypt 'hello' you'd substitute as follows,
```
              abcdefghijklmnopqrstuvwxyz
  hello ==>   |||||||||||||||||||||||||| ==> bshhk
              wednsaybcfghijklmopqrtuvxz

```             

hello encrypts into bshhk with the keyword wednesday. This cipher also uses lower case letters only.

Good Luck.

Difficulty: EASY
Tags: String algorithms

Starter code:
def keyword_cipher(msg, keyword):
	

Solutions:
abc = 'abcdefghijklmnopqrstuvwxyz'

def keyword_cipher(s, keyword, key=''):
	for c in keyword + abc:
		if c not in key:
			key += c
	return s.lower().translate(str.maketrans(abc, key))


from string import ascii_lowercase

def keyword_cipher(a, b):
	return a.lower().translate(str.maketrans(ascii_lowercase, ''.join(dict.fromkeys(b + ascii_lowercase))))


from string import ascii_lowercase as low
from itertools import filterfalse, chain

def keyword_cipher(msg, keyword):
	D = dict.fromkeys(keyword)
	cypher = ''.join(chain(D.keys(), filterfalse(D.__contains__, low)))
	return msg.lower().translate(str.maketrans(low, cypher))


keyword_cipher = lambda m, k, s='abcdefghijklmnopqrstuvwxyz': m.lower().translate(str.maketrans(s, ''.join(sorted(set(k), key=k.index) + [i for i in s if i not in k])))


from string import ascii_lowercase

def keyword_cipher(msg, keyword):
	key = list(dict.fromkeys(keyword + ascii_lowercase).keys())
	return ''.join((key[ascii_lowercase.index(c)] if c in key else c for c in msg.lower()))


def keyword_cipher(msg, keyword):
	abc = 'abcdefghijklmnopqrstuvwxyz'
	return msg.lower().translate(str.maketrans(abc, ''.join(dict.fromkeys(keyword)) + ''.join((c for c in abc if c not in keyword))))


from string import ascii_lowercase

def keyword_cipher(msg, keyword):
	msg = msg.lower()
	keyword = keyword.lower()
	subs = ''.join(dict.fromkeys(keyword)) + ''.join((c for c in ascii_lowercase if c not in keyword))
	tbl = str.maketrans(ascii_lowercase, subs)
	return msg.translate(tbl)


lowers = 'abcdefghijklmnopqrstuvwxyz '

def keyword_cipher(msg, keyword):
	key = ''.join(sorted(lowers, key=f'{keyword.lower()}{lowers}'.index))
	return ''.join((key[lowers.index(char)] for char in msg.lower()))


from string import ascii_lowercase
from collections import OrderedDict

def keyword_cipher(msg, keyword):
	return msg.lower().translate(str.maketrans(ascii_lowercase, ''.join(OrderedDict.fromkeys(keyword.lower() + ascii_lowercase).keys())))


import string

def keyword_cipher(msg, keyword):
	s = []
	for i in keyword.lower():
		if i not in s:
			s.append(i)
	return msg.lower().translate(str.maketrans(string.ascii_lowercase, ''.join(s + [i for i in string.ascii_lowercase if i not in keyword]).lower()))