mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 06:48:09 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
f06ea41b02
commit
60038f51d0
|
@ -33,41 +33,41 @@
|
||||||
"source": [
|
"source": [
|
||||||
"class PlayFire:\n",
|
"class PlayFire:\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" PlayFire class implements the Playfair \n",
|
" PlayFire class implements the Playfair\n",
|
||||||
" cipher for encryption and decryption of messages.\n",
|
" cipher for encryption and decryption of messages.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" The Playfair cipher is a digraph substitution \n",
|
" The Playfair cipher is a digraph substitution\n",
|
||||||
" cipher that encrypts pairs of letters. It requires a key, which\n",
|
" cipher that encrypts pairs of letters. It requires a key, which\n",
|
||||||
" is used to create a 6x6 matrix of letters and \n",
|
" is used to create a 6x6 matrix of letters and\n",
|
||||||
" digits, and processes the message in pairs.\n",
|
" digits, and processes the message in pairs.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Attributes:\n",
|
" Attributes:\n",
|
||||||
" key (str): The key used to generate the matrix.\n",
|
" key (str): The key used to generate the matrix.\n",
|
||||||
" key_matrix (list): The 6x6 matrix used for \n",
|
" key_matrix (list): The 6x6 matrix used for\n",
|
||||||
" encryption and decryption.extra (str): The extra character \n",
|
" encryption and decryption.extra (str): The extra character\n",
|
||||||
" used to pad the message if the length is odd (default is 'x').\n",
|
" used to pad the message if the length is odd (default is 'x').\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Methods:\n",
|
" Methods:\n",
|
||||||
" __verify_key(key): Verifies that the key is \n",
|
" __verify_key(key): Verifies that the key is\n",
|
||||||
" valid (contains unique characters).\n",
|
" valid (contains unique characters).\n",
|
||||||
" __make_matrix(): Creates a 6x6 matrix using \n",
|
" __make_matrix(): Creates a 6x6 matrix using\n",
|
||||||
" the key and the remaining letters/digits.\n",
|
" the key and the remaining letters/digits.\n",
|
||||||
" find_idx(pair): Finds the positions (row and column indices) \n",
|
" find_idx(pair): Finds the positions (row and column indices)\n",
|
||||||
" of the pair of characters in the matrix.\n",
|
" of the pair of characters in the matrix.\n",
|
||||||
" encrypt(msg): Encrypts the given message using \n",
|
" encrypt(msg): Encrypts the given message using\n",
|
||||||
" the Playfair cipher.\n",
|
" the Playfair cipher.\n",
|
||||||
" decrypt(msg): Decrypts the given encrypted \n",
|
" decrypt(msg): Decrypts the given encrypted\n",
|
||||||
" message using the Playfair cipher.\n",
|
" message using the Playfair cipher.\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def __init__(self, key, extra=\"x\"):\n",
|
" def __init__(self, key, extra=\"x\"):\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" Initializes the PlayFire cipher with a key and \n",
|
" Initializes the PlayFire cipher with a key and\n",
|
||||||
" an optional extra character for padding.\n",
|
" an optional extra character for padding.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Parameters:\n",
|
" Parameters:\n",
|
||||||
" key (str): The key to generate the cipher matrix.\n",
|
" key (str): The key to generate the cipher matrix.\n",
|
||||||
" extra (str, optional): The character used for \n",
|
" extra (str, optional): The character used for\n",
|
||||||
" padding the message if its length is odd. Defaults to 'x'.\n",
|
" padding the message if its length is odd. Defaults to 'x'.\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" self.key = self.__verify_key(key)\n",
|
" self.key = self.__verify_key(key)\n",
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
" key (str): The key to verify.\n",
|
" key (str): The key to verify.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Returns:\n",
|
" Returns:\n",
|
||||||
" str: The valid key if it contains only unique \n",
|
" str: The valid key if it contains only unique\n",
|
||||||
" characters, else prints an error.\n",
|
" characters, else prints an error.\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" keyy = []\n",
|
" keyy = []\n",
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
" def __make_matrix(self):\n",
|
" def __make_matrix(self):\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" Creates a 6x6 matrix from the key by filling \n",
|
" Creates a 6x6 matrix from the key by filling\n",
|
||||||
" in remaining characters of the alphabet and digits.\n",
|
" in remaining characters of the alphabet and digits.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Returns:\n",
|
" Returns:\n",
|
||||||
|
@ -115,15 +115,15 @@
|
||||||
"\n",
|
"\n",
|
||||||
" def find_idx(self, pair):\n",
|
" def find_idx(self, pair):\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" Finds the row and column indices of the \n",
|
" Finds the row and column indices of the\n",
|
||||||
" characters in the matrix.\n",
|
" characters in the matrix.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Parameters:\n",
|
" Parameters:\n",
|
||||||
" pair (list): A pair of characters whose \n",
|
" pair (list): A pair of characters whose\n",
|
||||||
" positions are to be found in the matrix.\n",
|
" positions are to be found in the matrix.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Returns:\n",
|
" Returns:\n",
|
||||||
" list: A list containing the row and column \n",
|
" list: A list containing the row and column\n",
|
||||||
" indices of both characters in the matrix.\n",
|
" indices of both characters in the matrix.\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" idxs = [6, 6]\n",
|
" idxs = [6, 6]\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user