From d62ebf7274ae69e689bcec73ac0400e7f827f4ba Mon Sep 17 00:00:00 2001 From: Vivek Date: Sat, 20 Jun 2026 11:33:40 +0530 Subject: [PATCH 1/7] corrected the typos --- strings/camel_case_to_snake_case.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/camel_case_to_snake_case.py b/strings/camel_case_to_snake_case.py index 582907be2edb..a01b8e4c06bb 100644 --- a/strings/camel_case_to_snake_case.py +++ b/strings/camel_case_to_snake_case.py @@ -5,8 +5,8 @@ def camel_to_snake_case(input_str: str) -> str: >>> camel_to_snake_case("someRandomString") 'some_random_string' - >>> camel_to_snake_case("SomeRandomStr#ng") - 'some_random_str_ng' + >>> camel_to_snake_case("SomeRandomString") + 'some_random_string' >>> camel_to_snake_case("123someRandom123String123") '123_some_random_123_string_123' From 4e9b21ef6110de4a96a08573725d37a270fc33ad Mon Sep 17 00:00:00 2001 From: Vivek Date: Sat, 20 Jun 2026 16:52:56 +0530 Subject: [PATCH 2/7] added the docstrings in the functions --- strings/frequency_finder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/strings/frequency_finder.py b/strings/frequency_finder.py index 98720dc36d6e..24bef4050c3b 100644 --- a/strings/frequency_finder.py +++ b/strings/frequency_finder.py @@ -36,6 +36,9 @@ def get_letter_count(message: str) -> dict[str, int]: + '''get_letter_count() is a function that takes message as parameter which is + supposed to be the string. and it returns a dictionary where string is a key + and integer is a value.''' letter_count = dict.fromkeys(string.ascii_uppercase, 0) for letter in message.upper(): if letter in LETTERS: @@ -45,6 +48,7 @@ def get_letter_count(message: str) -> dict[str, int]: def get_item_at_index_zero(x: tuple) -> str: + '''It takes x as parameter which is tuple and returns a string.''' return x[0] From ea72a2c3871189144401d75305a42cbe0cd0615c Mon Sep 17 00:00:00 2001 From: Vivek Date: Sun, 21 Jun 2026 20:14:31 +0530 Subject: [PATCH 3/7] added new file of secret_language --- strings/Secret_language.py | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 strings/Secret_language.py diff --git a/strings/Secret_language.py b/strings/Secret_language.py new file mode 100644 index 000000000000..3621c51a9b00 --- /dev/null +++ b/strings/Secret_language.py @@ -0,0 +1,53 @@ +# Encoding & Decoding + +import random +import string + +def random_chars() -> str: + ''' + Adds random 3 charaters to the string. + + ''' + return ''.join(random.choices(string.ascii_letters, k=3)) + +def random_digits() -> str: + ''' + Adds 3 random digits to the string. + ''' + + return ''.join(random.choices(string.digits, k=3)) + +def encode(code) -> str: + ''' + Encodes the code by shifting the first character to the end of the original string, + and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters. + unless the length of the code exceeds 3 or equals to it.''' + + if len(code) >= 3: + code = code[1:] + code[0] + code = random_chars() + random_digits() + code + random_digits() + random_chars() + else: + code = code[::-1] + code = random_chars() + random_digits() + code + random_digits() + random_chars() + return code + +def decode(code) -> str: + ''' + decodes the encoded string by removing the randomly added characters and reversing the shift + + ''' + + code = code[6:-6] + if len(code) >= 3: + code = code[-1] + code[:-1] + else: + code = code[::-1] + return code + +if __name__ == "__main__": + code = input("Enter the code: ") + encoded = encode(code) + decoded = decode(encoded) + print(f"Original → {code}") + print(f"Encoded → {encoded}") + print(f"Decoded → {decoded}") \ No newline at end of file From cb237ed2095a60e62d73afd8b17c1207cc1fb4f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 14:52:34 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/Secret_language.py | 47 ++++++++++++++++++++++--------------- strings/frequency_finder.py | 8 +++---- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/strings/Secret_language.py b/strings/Secret_language.py index 3621c51a9b00..c902fbe26ecc 100644 --- a/strings/Secret_language.py +++ b/strings/Secret_language.py @@ -3,40 +3,48 @@ import random import string + def random_chars() -> str: - ''' + """ Adds random 3 charaters to the string. - - ''' - return ''.join(random.choices(string.ascii_letters, k=3)) + + """ + return "".join(random.choices(string.ascii_letters, k=3)) + def random_digits() -> str: - ''' + """ Adds 3 random digits to the string. - ''' - - return ''.join(random.choices(string.digits, k=3)) + """ + + return "".join(random.choices(string.digits, k=3)) + def encode(code) -> str: - ''' + """ Encodes the code by shifting the first character to the end of the original string, and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters. - unless the length of the code exceeds 3 or equals to it.''' - + unless the length of the code exceeds 3 or equals to it.""" + if len(code) >= 3: code = code[1:] + code[0] - code = random_chars() + random_digits() + code + random_digits() + random_chars() + code = ( + random_chars() + random_digits() + code + random_digits() + random_chars() + ) else: code = code[::-1] - code = random_chars() + random_digits() + code + random_digits() + random_chars() + code = ( + random_chars() + random_digits() + code + random_digits() + random_chars() + ) return code + def decode(code) -> str: - ''' + """ decodes the encoded string by removing the randomly added characters and reversing the shift - - ''' - + + """ + code = code[6:-6] if len(code) >= 3: code = code[-1] + code[:-1] @@ -44,10 +52,11 @@ def decode(code) -> str: code = code[::-1] return code + if __name__ == "__main__": code = input("Enter the code: ") encoded = encode(code) - decoded = decode(encoded) + decoded = decode(encoded) print(f"Original → {code}") print(f"Encoded → {encoded}") - print(f"Decoded → {decoded}") \ No newline at end of file + print(f"Decoded → {decoded}") diff --git a/strings/frequency_finder.py b/strings/frequency_finder.py index 24bef4050c3b..e9da49799cc8 100644 --- a/strings/frequency_finder.py +++ b/strings/frequency_finder.py @@ -36,9 +36,9 @@ def get_letter_count(message: str) -> dict[str, int]: - '''get_letter_count() is a function that takes message as parameter which is - supposed to be the string. and it returns a dictionary where string is a key - and integer is a value.''' + """get_letter_count() is a function that takes message as parameter which is + supposed to be the string. and it returns a dictionary where string is a key + and integer is a value.""" letter_count = dict.fromkeys(string.ascii_uppercase, 0) for letter in message.upper(): if letter in LETTERS: @@ -48,7 +48,7 @@ def get_letter_count(message: str) -> dict[str, int]: def get_item_at_index_zero(x: tuple) -> str: - '''It takes x as parameter which is tuple and returns a string.''' + """It takes x as parameter which is tuple and returns a string.""" return x[0] From cb408bfe17d5011e759d685866a706622ac964a4 Mon Sep 17 00:00:00 2001 From: Vivek Date: Sun, 21 Jun 2026 20:29:17 +0530 Subject: [PATCH 5/7] resolved all the issues --- strings/Secret_language.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/Secret_language.py b/strings/Secret_language.py index 3621c51a9b00..6f66b03d1d49 100644 --- a/strings/Secret_language.py +++ b/strings/Secret_language.py @@ -17,7 +17,7 @@ def random_digits() -> str: return ''.join(random.choices(string.digits, k=3)) -def encode(code) -> str: +def encode(code: str) -> str: ''' Encodes the code by shifting the first character to the end of the original string, and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters. @@ -31,7 +31,7 @@ def encode(code) -> str: code = random_chars() + random_digits() + code + random_digits() + random_chars() return code -def decode(code) -> str: +def decode(code: str) -> str: ''' decodes the encoded string by removing the randomly added characters and reversing the shift From 4115d6853609776711a1e37ccb474438cf1975a2 Mon Sep 17 00:00:00 2001 From: Vivek Date: Sun, 21 Jun 2026 20:39:36 +0530 Subject: [PATCH 6/7] modified the file --- strings/Secret_language.py | 72 +++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/strings/Secret_language.py b/strings/Secret_language.py index a959cb663f15..33f457656b7e 100644 --- a/strings/Secret_language.py +++ b/strings/Secret_language.py @@ -6,55 +6,69 @@ def random_chars() -> str: """ - Adds random 3 charaters to the string. + Generate a random string of 3 ASCII letters. + >>> import random + >>> random.seed(42) + >>> random_chars() + 'ZoX' """ - return "".join(random.choices(string.ascii_letters, k=3)) + return ''.join(random.choices(string.ascii_letters, k=3)) def random_digits() -> str: """ - Adds 3 random digits to the string. - """ + Generate a random string of 3 digits. - return "".join(random.choices(string.digits, k=3)) + >>> import random + >>> random.seed(42) + >>> random_digits() + '638' + """ + return ''.join(random.choices(string.digits, k=3)) -<<<<<<< HEAD def encode(code: str) -> str: - ''' -======= -def encode(code) -> str: """ ->>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9 - Encodes the code by shifting the first character to the end of the original string, - and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters. - unless the length of the code exceeds 3 or equals to it.""" + Encode a string by shifting the first character to the end and + wrapping it with random padding of 3 letters and 3 digits on each side. + + Reference: https://en.wikipedia.org/wiki/Caesar_cipher + >>> import random + >>> random.seed(42) + >>> encode('hello') + 'ZoX638elloh415mJu' + + >>> import random + >>> random.seed(42) + >>> encode('hi') + 'ZoX638ih415mJu' + """ if len(code) >= 3: code = code[1:] + code[0] - code = ( - random_chars() + random_digits() + code + random_digits() + random_chars() - ) + code = random_chars() + random_digits() + code + random_digits() + random_chars() else: code = code[::-1] - code = ( - random_chars() + random_digits() + code + random_digits() + random_chars() - ) + code = random_chars() + random_digits() + code + random_digits() + random_chars() return code -<<<<<<< HEAD -def decode(code: str) -> str: - ''' -======= -def decode(code) -> str: +def decode(code: str) -> str: """ ->>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9 - decodes the encoded string by removing the randomly added characters and reversing the shift - + Decode an encoded string by stripping the random padding and + reversing the character shift. + + >>> import random + >>> random.seed(42) + >>> decode(encode('hello')) + 'hello' + + >>> import random + >>> random.seed(42) + >>> decode(encode('hi')) + 'hi' """ - code = code[6:-6] if len(code) >= 3: code = code[-1] + code[:-1] @@ -69,4 +83,4 @@ def decode(code) -> str: decoded = decode(encoded) print(f"Original → {code}") print(f"Encoded → {encoded}") - print(f"Decoded → {decoded}") + print(f"Decoded → {decoded}") \ No newline at end of file From 9590b2da59156ded77ab492c1cd1f5cc19295306 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 15:10:25 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/Secret_language.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/strings/Secret_language.py b/strings/Secret_language.py index 33f457656b7e..7d090439a3d8 100644 --- a/strings/Secret_language.py +++ b/strings/Secret_language.py @@ -13,7 +13,7 @@ def random_chars() -> str: >>> random_chars() 'ZoX' """ - return ''.join(random.choices(string.ascii_letters, k=3)) + return "".join(random.choices(string.ascii_letters, k=3)) def random_digits() -> str: @@ -25,7 +25,7 @@ def random_digits() -> str: >>> random_digits() '638' """ - return ''.join(random.choices(string.digits, k=3)) + return "".join(random.choices(string.digits, k=3)) def encode(code: str) -> str: @@ -47,10 +47,14 @@ def encode(code: str) -> str: """ if len(code) >= 3: code = code[1:] + code[0] - code = random_chars() + random_digits() + code + random_digits() + random_chars() + code = ( + random_chars() + random_digits() + code + random_digits() + random_chars() + ) else: code = code[::-1] - code = random_chars() + random_digits() + code + random_digits() + random_chars() + code = ( + random_chars() + random_digits() + code + random_digits() + random_chars() + ) return code @@ -83,4 +87,4 @@ def decode(code: str) -> str: decoded = decode(encoded) print(f"Original → {code}") print(f"Encoded → {encoded}") - print(f"Decoded → {decoded}") \ No newline at end of file + print(f"Decoded → {decoded}")