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