From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/5] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/5] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From 8dff4d408201a576363c8bd6c4cb7b6ed148eb4c Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 15 Apr 2024 09:55:40 +0530 Subject: [PATCH 3/5] crypto-square --- .../__pycache__/crypto_square.cpython-39.pyc | Bin 0 -> 709 bytes ...to_square_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 2628 bytes practice/crypto-square/crypto_square.py | 30 +++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc create mode 100644 practice/crypto-square/__pycache__/crypto_square_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc b/practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..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jM)rk?daiy5B4+n;d-2VWt>SW0+Z&uWPgdzkNy{IY2apv+h-xy z2>zo~?9W?9k5I@{Xb|gNILux65(go%mjPUoE6?^L_#hR(YAi?C)~`R-A1-fJ z7d!Xqv8m#QWm}7;tZ~!Ugu(gYAu97z!Hrc0ogjZ% oT)!pq_e$oUK~EpTPL802Id>tCy#Ch(8;3SFYa6BC^V+q40r(!xVE_OC literal 0 HcmV?d00001 diff --git a/practice/crypto-square/crypto_square.py b/practice/crypto-square/crypto_square.py index f0c89b3..153503f 100644 --- a/practice/crypto-square/crypto_square.py +++ b/practice/crypto-square/crypto_square.py @@ -1,2 +1,30 @@ +import math +import re + def cipher_text(plain_text): - pass + plain_text = re.sub(r'\W+', '', plain_text).lower() + + if not plain_text: + return "" + + c = math.ceil(math.sqrt(len(plain_text))) + r = len(plain_text) // c + if len(plain_text) % c != 0: + r += 1 + + rows = [] + for i in range(r): + row = plain_text[i*c:(i+1)*c].ljust(c) + rows.append(row) + + encoded_text = "" + for i in range(c): + for row in rows: + encoded_text += row[i] + + chunks = [] + for i in range(c): + chunk = encoded_text[i*r:(i+1)*r] + chunks.append(chunk) + + return ' '.join(chunks) \ No newline at end of file From 4947b8c5a0aa4baa56a33d395c0df8520fe4af71 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 03:09:53 +0530 Subject: [PATCH 4/5] removed cache files --- .../__pycache__/crypto_square.cpython-39.pyc | Bin 709 -> 0 bytes ...rypto_square_test.cpython-39-pytest-6.2.4.pyc | Bin 2628 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc delete mode 100644 practice/crypto-square/__pycache__/crypto_square_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc b/practice/crypto-square/__pycache__/crypto_square.cpython-39.pyc deleted file mode 100644 index a3f4d09fa8e188bed463154b2a7eaec9c08933b5..0000000000000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?daiy5B4+n;d-2VWt>SW0+Z&uWPgdzkNy{IY2apv+h-xy z2>zo~?9W?9k5I@{Xb|gNILux65(go%mjPUoE6?^L_#hR(YAi?C)~`R-A1-fJ z7d!Xqv8m#QWm}7;tZ~!Ugu(gYAu97z!Hrc0ogjZ% oT)!pq_e$oUK~EpTPL802Id>tCy#Ch(8;3SFYa6BC^V+q40r(!xVE_OC From 6425496200368c89b531317771bf36509113f3b3 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 16:01:58 +0530 Subject: [PATCH 5/5] improved the code --- practice/crypto-square/crypto_square.py | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/practice/crypto-square/crypto_square.py b/practice/crypto-square/crypto_square.py index 153503f..fc6bfd9 100644 --- a/practice/crypto-square/crypto_square.py +++ b/practice/crypto-square/crypto_square.py @@ -1,30 +1,57 @@ import math import re + def cipher_text(plain_text): + """ + Encodes a plain text message into a cipher text using the square code method. + + The square code method involves arranging the plain text in a rectangle + and then reading the text in columns, going from left to right. + + Args: + plain_text (str): The plain text message to encode. + + Returns: + str: The encoded cipher text. + + Raises: + ValueError: If the input is not a string. + + Examples: + >>> cipher_text("If man was meant to stay on the ground, god would have given us roots.") + 'imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau' + """ + # Remove all non-alphanumeric characters and convert to lower case plain_text = re.sub(r'\W+', '', plain_text).lower() + # If the plain text is empty, return an empty string if not plain_text: return "" + # Calculate the number of columns and rows for the rectangle c = math.ceil(math.sqrt(len(plain_text))) r = len(plain_text) // c if len(plain_text) % c != 0: r += 1 + # Split the plain text into rows rows = [] for i in range(r): row = plain_text[i*c:(i+1)*c].ljust(c) rows.append(row) + # Read the text in columns to get the encoded text encoded_text = "" for i in range(c): for row in rows: encoded_text += row[i] + # Split the encoded text into chunks of length r chunks = [] for i in range(c): chunk = encoded_text[i*r:(i+1)*r] chunks.append(chunk) + # Join the chunks with spaces to get the final cipher text return ' '.join(chunks) \ No newline at end of file