def encipher_hill(msg, key, symbols=None, pad='Q'):
 assert key.is_square
 assert (len(pad) == 1)
 (msg, pad, A) = _prep(msg, pad, symbols)
 map = {c: i for (i, c) in enumerate(A)}
 P = [map[c] for c in msg]
 N = len(A)
 k = key.cols
 n = len(P)
 (m, r) = divmod(n, k)
 if r:
  P = (P + ([map[pad]] * (k - r)))
  m += 1
 rv = ''.join([A[(c % N)] for j in range(m) for c in list((key * Matrix(k, 1, [P[i] for i in range((k * j), (k * (j + 1)))])))])
 return rv

def encipher_hill ( msg , key , symbols = None , pad = 'Q' ) : assert key . is_square assert ( len ( pad ) == 1 ) ( msg , pad , A ) = _prep ( msg , pad , symbols ) map = { c : i for ( i , c ) in enumerate ( A ) } P = [ map [ c ] for c in msg ] N = len ( A ) k = key . cols n = len ( P ) ( m , r ) = divmod ( n , k ) if r : P = ( P + ( [ map [ pad ] ] * ( k - r ) ) ) m += 1 rv = '' . join ( [ A [ ( c % N ) ] for j in range ( m ) for c in list ( ( key * Matrix ( k , 1 , [ P [ i ] for i in range ( ( k * j ) , ( k * ( j + 1 ) ) ) ] ) ) ) ] ) return rv
return the hill cipher encryption of msg .