def encipher_affine(msg, key, symbols=None, _inverse=False):
 (msg, _, A) = _prep(msg, '', symbols)
 N = len(A)
 (a, b) = key
 assert (gcd(a, N) == 1)
 if _inverse:
  c = mod_inverse(a, N)
  d = ((- b) * c)
  (a, b) = (c, d)
 B = ''.join([A[(((a * i) + b) % N)] for i in range(N)])
 return translate(msg, A, B)

def encipher_affine ( msg , key , symbols = None , _inverse = False ) : ( msg , _ , A ) = _prep ( msg , '' , symbols ) N = len ( A ) ( a , b ) = key assert ( gcd ( a , N ) == 1 ) if _inverse : c = mod_inverse ( a , N ) d = ( ( - b ) * c ) ( a , b ) = ( c , d ) B = '' . join ( [ A [ ( ( ( a * i ) + b ) % N ) ] for i in range ( N ) ] ) return translate ( msg , A , B )
performs the affine cipher encryption on plaintext msg .