|
33 | 33 | "source": [
|
34 | 34 | "class PlayFire:\n",
|
35 | 35 | " \"\"\"\n",
|
36 |
| - " PlayFire class implements the Playfair cipher for encryption and decryption of messages.\n", |
| 36 | + " PlayFire class implements the Playfair \n", |
| 37 | + " cipher for encryption and decryption of messages.\n", |
37 | 38 | "\n",
|
38 |
| - " The Playfair cipher is a digraph substitution cipher that encrypts pairs of letters. It requires a key, which\n", |
39 |
| - " is used to create a 6x6 matrix of letters and digits, and processes the message in pairs.\n", |
| 39 | + " The Playfair cipher is a digraph substitution \n", |
| 40 | + " cipher that encrypts pairs of letters. It requires a key, which\n", |
| 41 | + " is used to create a 6x6 matrix of letters and \n", |
| 42 | + " digits, and processes the message in pairs.\n", |
40 | 43 | "\n",
|
41 | 44 | " Attributes:\n",
|
42 | 45 | " key (str): The key used to generate the matrix.\n",
|
43 |
| - " key_matrix (list): The 6x6 matrix used for encryption and decryption.\n", |
44 |
| - " extra (str): The extra character used to pad the message if the length is odd (default is 'x').\n", |
| 46 | + " key_matrix (list): The 6x6 matrix used for \n", |
| 47 | + " encryption and decryption.extra (str): The extra character \n", |
| 48 | + " used to pad the message if the length is odd (default is 'x').\n", |
45 | 49 | "\n",
|
46 | 50 | " Methods:\n",
|
47 |
| - " __verify_key(key): Verifies that the key is valid (contains unique characters).\n", |
48 |
| - " __make_matrix(): Creates a 6x6 matrix using the key and the remaining letters/digits.\n", |
49 |
| - " find_idx(pair): Finds the positions (row and column indices) of the pair of characters in the matrix.\n", |
50 |
| - " encrypt(msg): Encrypts the given message using the Playfair cipher.\n", |
51 |
| - " decrypt(msg): Decrypts the given encrypted message using the Playfair cipher.\n", |
| 51 | + " __verify_key(key): Verifies that the key is \n", |
| 52 | + " valid (contains unique characters).\n", |
| 53 | + " __make_matrix(): Creates a 6x6 matrix using \n", |
| 54 | + " the key and the remaining letters/digits.\n", |
| 55 | + " find_idx(pair): Finds the positions (row and column indices) \n", |
| 56 | + " of the pair of characters in the matrix.\n", |
| 57 | + " encrypt(msg): Encrypts the given message using \n", |
| 58 | + " the Playfair cipher.\n", |
| 59 | + " decrypt(msg): Decrypts the given encrypted \n", |
| 60 | + " message using the Playfair cipher.\n", |
52 | 61 | " \"\"\"\n",
|
53 | 62 | "\n",
|
54 | 63 | " def __init__(self, key, extra=\"x\"):\n",
|
55 | 64 | " \"\"\"\n",
|
56 |
| - " Initializes the PlayFire cipher with a key and an optional extra character for padding.\n", |
| 65 | + " Initializes the PlayFire cipher with a key and \n", |
| 66 | + " an optional extra character for padding.\n", |
57 | 67 | "\n",
|
58 | 68 | " Parameters:\n",
|
59 | 69 | " key (str): The key to generate the cipher matrix.\n",
|
60 |
| - " extra (str, optional): The character used for padding the message if its length is odd. Defaults to 'x'.\n", |
| 70 | + " extra (str, optional): The character used for \n", |
| 71 | + " padding the message if its length is odd. Defaults to 'x'.\n", |
61 | 72 | " \"\"\"\n",
|
62 | 73 | " self.key = self.__verify_key(key)\n",
|
63 | 74 | " self.key_matrix = self.__make_matrix()\n",
|
|
71 | 82 | " key (str): The key to verify.\n",
|
72 | 83 | "\n",
|
73 | 84 | " Returns:\n",
|
74 |
| - " str: The valid key if it contains only unique characters, else prints an error.\n", |
| 85 | + " str: The valid key if it contains only unique \n", |
| 86 | + " characters, else prints an error.\n", |
75 | 87 | " \"\"\"\n",
|
76 | 88 | " keyy = []\n",
|
77 | 89 | " for i in key:\n",
|
|
84 | 96 | "\n",
|
85 | 97 | " def __make_matrix(self):\n",
|
86 | 98 | " \"\"\"\n",
|
87 |
| - " Creates a 6x6 matrix from the key by filling in remaining characters of the alphabet and digits.\n", |
| 99 | + " Creates a 6x6 matrix from the key by filling \n", |
| 100 | + " in remaining characters of the alphabet and digits.\n", |
88 | 101 | "\n",
|
89 | 102 | " Returns:\n",
|
90 | 103 | " list: A 6x6 matrix for encryption and decryption.\n",
|
|
102 | 115 | "\n",
|
103 | 116 | " def find_idx(self, pair):\n",
|
104 | 117 | " \"\"\"\n",
|
105 |
| - " Finds the row and column indices of the characters in the matrix.\n", |
| 118 | + " Finds the row and column indices of the \n", |
| 119 | + " characters in the matrix.\n", |
106 | 120 | "\n",
|
107 | 121 | " Parameters:\n",
|
108 |
| - " pair (list): A pair of characters whose positions are to be found in the matrix.\n", |
| 122 | + " pair (list): A pair of characters whose \n", |
| 123 | + " positions are to be found in the matrix.\n", |
109 | 124 | "\n",
|
110 | 125 | " Returns:\n",
|
111 |
| - " list: A list containing the row and column indices of both characters in the matrix.\n", |
| 126 | + " list: A list containing the row and column \n", |
| 127 | + " indices of both characters in the matrix.\n", |
112 | 128 | " \"\"\"\n",
|
113 | 129 | " idxs = [6, 6]\n",
|
114 | 130 | " for i in range(6):\n",
|
|
0 commit comments