From 37ee3980456adf06cebf728f374d0fe930da237d Mon Sep 17 00:00:00 2001 From: sh1ney Date: Mon, 3 Nov 2025 20:01:45 +0300 Subject: [PATCH] Add hide-secret.cpp --- hide-secret.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 hide-secret.cpp diff --git a/hide-secret.cpp b/hide-secret.cpp new file mode 100755 index 0000000..ea09801 --- /dev/null +++ b/hide-secret.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +void hide_secret(char* const text, const char* const secret) { + if (!text || !secret) { return; } + + const unsigned textlen = strlen(text); + const unsigned secretlen = strlen(secret); + + if (textlen < 1 || secretlen < 1 || textlen < secretlen) { return; } + + std::vector indices; + + for (size_t i = 0; i < textlen - secretlen + 1; i++) { + bool isSubstring = true; + + for (size_t j = 0; j < secretlen; j++) { + if (text[i+j] != secret[j]) { + isSubstring = false; + break; + } + } + + if (isSubstring) { indices.push_back(i); } + } + + for (size_t index : indices) { + for (size_t j = 0; j < secretlen; j++) { + text[index + j] = 'x'; + } + } +}