From f5b4902c1760f6a8fe3d9f4867874b4c63989af2 Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:38:25 +0500 Subject: [PATCH 1/6] Create hide-secret.cpp --- hide-secret.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 hide-secret.cpp diff --git a/hide-secret.cpp b/hide-secret.cpp new file mode 100644 index 0000000..25d4e6f --- /dev/null +++ b/hide-secret.cpp @@ -0,0 +1,28 @@ +void check_and_change(char* const text, const char* const secret, const int shift) +{ + int i = 0; + while (secret[i] != '\0') + { + if (secret[i] != text[i + shift]) + { + return; + } + i++; + } + + i = 0; + while (secret[i] != '\0') + { + text[i + shift] = '*'; + i++; + } +} + +void hide_secret(char* const text, const char* const secret) +{ + int i = 0; + while (text[i] != '\0') + { + check_and_change(text, secret, ++i); + } +} \ No newline at end of file From 4da291666c2da8c74d49ba82ba2164f33874f047 Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:43:19 +0500 Subject: [PATCH 2/6] Update hide-secret.cpp --- hide-secret.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hide-secret.cpp b/hide-secret.cpp index 25d4e6f..45a5a04 100644 --- a/hide-secret.cpp +++ b/hide-secret.cpp @@ -13,7 +13,7 @@ void check_and_change(char* const text, const char* const secret, const int shif i = 0; while (secret[i] != '\0') { - text[i + shift] = '*'; + text[i + shift] = 'x'; i++; } } From 71ee7e4cedc1989e9bc529c5abc64740596c58f3 Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Thu, 6 Nov 2025 01:58:01 +0500 Subject: [PATCH 3/6] Update hide-secret.cpp --- hide-secret.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hide-secret.cpp b/hide-secret.cpp index 45a5a04..10fc029 100644 --- a/hide-secret.cpp +++ b/hide-secret.cpp @@ -1,21 +1,27 @@ -void check_and_change(char* const text, const char* const secret, const int shift) +int check_and_change(char* const text, const char* const secret, + const int shift) { int i = 0; while (secret[i] != '\0') { if (secret[i] != text[i + shift]) { - return; + return shift; } i++; } + const int secret_len = i; + i = 0; - while (secret[i] != '\0') + while (i < secret_len && secret[i] != '\0') { text[i + shift] = 'x'; i++; + i = check_and_change(text, secret, i + shift) - shift; } + + return shift + i; } void hide_secret(char* const text, const char* const secret) @@ -23,6 +29,6 @@ void hide_secret(char* const text, const char* const secret) int i = 0; while (text[i] != '\0') { - check_and_change(text, secret, ++i); + i = check_and_change(text, secret, ++i); } } \ No newline at end of file From f550bd866be97ef1b4690df1d89a5b27e4661e84 Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Thu, 6 Nov 2025 02:17:48 +0500 Subject: [PATCH 4/6] check valid --- hide-secret.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hide-secret.cpp b/hide-secret.cpp index 10fc029..4118dc2 100644 --- a/hide-secret.cpp +++ b/hide-secret.cpp @@ -24,8 +24,25 @@ int check_and_change(char* const text, const char* const secret, return shift + i; } +int get_string_length(const char* const str) +{ + int i = 0; + while (str[i] != '\0') + { + i++; + } + return i; +} + void hide_secret(char* const text, const char* const secret) { + const int text_len = get_string_length(text); + const int secret_len = get_string_length(secret); + if (text_len <= 0 || secret_len <= 0 || text_len < secret_len) + { + return; + } + int i = 0; while (text[i] != '\0') { From 2983744a03d1b7249d28e83e5af0e3e6cb71c1c8 Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Thu, 6 Nov 2025 02:27:42 +0500 Subject: [PATCH 5/6] check nulptr --- hide-secret.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hide-secret.cpp b/hide-secret.cpp index 4118dc2..d1a3829 100644 --- a/hide-secret.cpp +++ b/hide-secret.cpp @@ -36,6 +36,11 @@ int get_string_length(const char* const str) void hide_secret(char* const text, const char* const secret) { + if (!text || !secret) + { + return; + } + const int text_len = get_string_length(text); const int secret_len = get_string_length(secret); if (text_len <= 0 || secret_len <= 0 || text_len < secret_len) @@ -46,6 +51,6 @@ void hide_secret(char* const text, const char* const secret) int i = 0; while (text[i] != '\0') { - i = check_and_change(text, secret, ++i); + i = check_and_change(text, secret, i) + 1; } } \ No newline at end of file From f0d1bd2e3375e0f67ed20cc36bac2fb5b04c53cb Mon Sep 17 00:00:00 2001 From: LegendaV <115637903+LegendaV@users.noreply.github.com> Date: Thu, 6 Nov 2025 03:04:57 +0500 Subject: [PATCH 6/6] Update hide-secret.cpp --- hide-secret.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hide-secret.cpp b/hide-secret.cpp index d1a3829..342f829 100644 --- a/hide-secret.cpp +++ b/hide-secret.cpp @@ -21,7 +21,7 @@ int check_and_change(char* const text, const char* const secret, i = check_and_change(text, secret, i + shift) - shift; } - return shift + i; + return shift + i - 1; } int get_string_length(const char* const str)