Skip to content

Commit 609a711

Browse files
committed
Update playfire.ipynb
1 parent 7becd05 commit 609a711

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

cryptography/playfire.ipynb

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,42 @@
3333
"source": [
3434
"class PlayFire:\n",
3535
" \"\"\"\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",
3738
"\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",
4043
"\n",
4144
" Attributes:\n",
4245
" 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",
4549
"\n",
4650
" 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",
5261
" \"\"\"\n",
5362
"\n",
5463
" def __init__(self, key, extra=\"x\"):\n",
5564
" \"\"\"\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",
5767
"\n",
5868
" Parameters:\n",
5969
" 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",
6172
" \"\"\"\n",
6273
" self.key = self.__verify_key(key)\n",
6374
" self.key_matrix = self.__make_matrix()\n",
@@ -71,7 +82,8 @@
7182
" key (str): The key to verify.\n",
7283
"\n",
7384
" 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",
7587
" \"\"\"\n",
7688
" keyy = []\n",
7789
" for i in key:\n",
@@ -84,7 +96,8 @@
8496
"\n",
8597
" def __make_matrix(self):\n",
8698
" \"\"\"\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",
88101
"\n",
89102
" Returns:\n",
90103
" list: A 6x6 matrix for encryption and decryption.\n",
@@ -102,13 +115,16 @@
102115
"\n",
103116
" def find_idx(self, pair):\n",
104117
" \"\"\"\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",
106120
"\n",
107121
" 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",
109124
"\n",
110125
" 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",
112128
" \"\"\"\n",
113129
" idxs = [6, 6]\n",
114130
" for i in range(6):\n",

0 commit comments

Comments
 (0)