mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +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": [
|
||||
"class PlayFire:\n",
|
||||
" \"\"\"\n",
|
||||
" PlayFire class implements the Playfair \n",
|
||||
" PlayFire class implements the Playfair\n",
|
||||
" cipher for encryption and decryption of messages.\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",
|
||||
" 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",
|
||||
"\n",
|
||||
" Attributes:\n",
|
||||
" key (str): The key used to generate the matrix.\n",
|
||||
" key_matrix (list): The 6x6 matrix used for \n",
|
||||
" encryption and decryption.extra (str): The extra character \n",
|
||||
" key_matrix (list): The 6x6 matrix used for\n",
|
||||
" encryption and decryption.extra (str): The extra character\n",
|
||||
" used to pad the message if the length is odd (default is 'x').\n",
|
||||
"\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",
|
||||
" __make_matrix(): Creates a 6x6 matrix using \n",
|
||||
" __make_matrix(): Creates a 6x6 matrix using\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",
|
||||
" encrypt(msg): Encrypts the given message using \n",
|
||||
" encrypt(msg): Encrypts the given message using\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",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def __init__(self, key, extra=\"x\"):\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",
|
||||
"\n",
|
||||
" Parameters:\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",
|
||||
" \"\"\"\n",
|
||||
" self.key = self.__verify_key(key)\n",
|
||||
|
@ -82,7 +82,7 @@
|
|||
" key (str): The key to verify.\n",
|
||||
"\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",
|
||||
" \"\"\"\n",
|
||||
" keyy = []\n",
|
||||
|
@ -96,7 +96,7 @@
|
|||
"\n",
|
||||
" def __make_matrix(self):\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",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
|
@ -115,15 +115,15 @@
|
|||
"\n",
|
||||
" def find_idx(self, pair):\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",
|
||||
"\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",
|
||||
"\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",
|
||||
" \"\"\"\n",
|
||||
" idxs = [6, 6]\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user