#!/usr/bin/env python

from pypher import converter


# TODO: add other key parameters (up, down, right, left)
# add key shorter than 25 and auto completion
def encrypt(message: str, key: str = "<KEY>", n: int = 3) -> str:
	"""
	1. build a 2D matrix of the key (5x5)
	2. take n first chars of message
	3. take the x and y of each chars
	4. map it like that x1x2x3...y1y2y3...
	5. repeat
	"""
	message = converter.normalize(message)
	key = key.upper()

	# built the 2D table of the key
	key_chunks = converter.split(key, 5)
	matrix = [list(chunk) for chunk in key_chunks]

	chunks = converter.split(message, n)
	for chunk in chunks:
		for letter in chunk:
			raise NotImplementedError()




def decrypt(crypted_message: str, key: str = "<KEY>", n: int = 3) -> str:
	crypted_message = converter.normalize(crypted_message)
	key = key.upper()

	# built the 2D table of the key
	key_chunks = converter.split(key, 5)
	matrix = [list(chunk) for chunk in key_chunks]

	chunks = converter.split(crypted_message, 2*n)
	message = ""
	for chunk in chunks:
		xs = list()
		ys = list()
		for letter in chunk[:n]:
			xs.append(key.index(letter) // 5)
		for letter in chunk[n:]:
			y = key.index(letter)
			while y >= 5:
				y -= 5
			ys.append(y)

		for x, y in zip(xs, ys):
			message += matrix[x][y]
	return message
#!/usr/bin/env python

from pypher import converter


# TODO: add other key parameters (up, down, right, left)
# add key shorter than 25 and auto completion
def encrypt(message: str, key: str = "<KEY>", n: int = 3) -> str:
	"""
	1. build a 2D matrix of the key (5x5)
	2. take n first chars of message
	3. take the x and y of each chars
	4. map it like that x1x2x3...y1y2y3...
	5. repeat
	"""
	message = converter.normalize(message)
	key = key.upper()

	# built the 2D table of the key
	key_chunks = converter.split(key, 5)
	matrix = [list(chunk) for chunk in key_chunks]

	chunks = converter.split(message, n)
	for chunk in chunks:
		for letter in chunk:
			raise NotImplementedError()




def decrypt(crypted_message: str, key: str = "<KEY>", n: int = 3) -> str:
	crypted_message = converter.normalize(crypted_message)
	key = key.upper()

	# built the 2D table of the key
	key_chunks = converter.split(key, 5)
	matrix = [list(chunk) for chunk in key_chunks]

	chunks = converter.split(crypted_message, 2*n)
	message = ""
	for chunk in chunks:
		xs = list()
		ys = list()
		for letter in chunk[:n]:
			xs.append(key.index(letter) // 5)
		for letter in chunk[n:]:
			y = key.index(letter)
			while y >= 5:
				y -= 5
			ys.append(y)

		for x, y in zip(xs, ys):
			message += matrix[x][y]
	return message
#!/usr/bin/env python # TODO: add other key parameters (up, down, right, left) # add key shorter than 25 and auto completion 1. build a 2D matrix of the key (5x5) 	2. take n first chars of message 	3. take the x and y of each chars 	4. map it like that x1x2x3...y1y2y3... 	5. repeat # built the 2D table of the key # built the 2D table of the key