
from string import ascii_lowercase, ascii_uppercase






def      lowerCamelCase__       (       __lowerCAmelCase						:						str       ):




   """simple docstring"""


   if not sentence:
      return ""
   lowerCAmelCase_      			=			dict(zip(__lowerCAmelCase					,							__lowerCAmelCase       )       )
   return lower_to_upper.get(sentence[0]					,							sentence[0]       ) + sentence[1:]


if __name__ == "__main__":
   from doctest import testmod

   testmod()





import itertools
import string
from collections.abc import Generator, Iterable






def      lowerCamelCase__       (       __lowerCAmelCase						:						Iterable[str]					,							__lowerCAmelCase						:						int       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			iter(__lowerCAmelCase       )
			while True:
						lowerCAmelCase_      			=			tuple(itertools.islice(__lowerCAmelCase					,							__lowerCAmelCase       )       )
						if not chunk:
									return
						yield chunk






def      lowerCamelCase__       (       __lowerCAmelCase						:						str       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			"".join([c.upper() for c in dirty if c in string.ascii_letters]       )
			lowerCAmelCase_      			=			""

			if len(__lowerCAmelCase       ) < 2:
						return dirty

			for i in range(len(__lowerCAmelCase       ) - 1       ):
						clean += dirty[i]

						if dirty[i] == dirty[i + 1]:
									clean += "X"

			clean += dirty[-1]

			if len(__lowerCAmelCase       ) & 1:
						clean += "X"

			return clean






def      lowerCamelCase__       (       __lowerCAmelCase						:						str       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			"ABCDEFGHIKLMNOPQRSTUVWXYZ"
			# we're using a list instead of a '2d' array because it makes the math
			# for setting up the table and doing the actual encoding/decoding simpler
			lowerCAmelCase_      			=			[]

			# copy key chars into the table if they are in `alphabet` ignoring duplicates
			for char in key.upper():
						if char not in table and char in alphabet:
									table.append(__lowerCAmelCase       )

    # fill the rest of the table in with the remaining alphabet chars
			for char in alphabet:
						if char not in table:
									table.append(__lowerCAmelCase       )

			return table






def      lowerCamelCase__       (       __lowerCAmelCase						:						str					,							__lowerCAmelCase						:						str       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			generate_table(__lowerCAmelCase       )
			lowerCAmelCase_      			=			prepare_input(__lowerCAmelCase       )
			lowerCAmelCase_      			=			""

			# https://en.wikipedia.org/wiki/Playfair_cipher#Description
			for chara, chara in chunker(__lowerCAmelCase					,							2       ):
						lowerCAmelCase_			,						lowerCAmelCase_      			=			divmod(table.index(__lowerCAmelCase       )					,							5       )
						lowerCAmelCase_			,						lowerCAmelCase_      			=			divmod(table.index(__lowerCAmelCase       )					,							5       )

						if rowa == rowa:
									ciphertext += table[rowa * 5 + (cola + 1) % 5]
									ciphertext += table[rowa * 5 + (cola + 1) % 5]
						elif cola == cola:
									ciphertext += table[((rowa + 1) % 5) * 5 + cola]
									ciphertext += table[((rowa + 1) % 5) * 5 + cola]
						else:  # rectangle
									ciphertext += table[rowa * 5 + cola]
									ciphertext += table[rowa * 5 + cola]

			return ciphertext






def      lowerCamelCase__       (       __lowerCAmelCase						:						str					,							__lowerCAmelCase						:						str       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			generate_table(__lowerCAmelCase       )
			lowerCAmelCase_      			=			""

			# https://en.wikipedia.org/wiki/Playfair_cipher#Description
			for chara, chara in chunker(__lowerCAmelCase					,							2       ):
						lowerCAmelCase_			,						lowerCAmelCase_      			=			divmod(table.index(__lowerCAmelCase       )					,							5       )
						lowerCAmelCase_			,						lowerCAmelCase_      			=			divmod(table.index(__lowerCAmelCase       )					,							5       )

						if rowa == rowa:
									plaintext += table[rowa * 5 + (cola - 1) % 5]
									plaintext += table[rowa * 5 + (cola - 1) % 5]
						elif cola == cola:
									plaintext += table[((rowa - 1) % 5) * 5 + cola]
									plaintext += table[((rowa - 1) % 5) * 5 + cola]
						else:  # rectangle
									plaintext += table[rowa * 5 + cola]
									plaintext += table[rowa * 5 + cola]

			return plaintext



