Claude 输出与受版权保护的 StackOverflow 代码匹配

2作者: randsp大约 1 个月前原帖
我请Claude生成一个C++实现的base64编码器,结果几乎与StackOverflow上的一个版本完全相同。我想这通常不会成为问题,除非发现StackOverflow的示例似乎源自受版权保护的代码。 StackOverflow相关评论链接:[StackOverflow评论](https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c#comment137345692_13935718) Claude版本: ```cpp std::string base64encode(const char* data, size_t length) { static const char* base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; std::string result; result.reserve(((length + 2) / 3) * 4); size_t i = 0; unsigned char char_array_3[3]; unsigned char char_array_4[4]; while (length--) { char_array_3[i++] = *(data++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (i = 0; i < 4; i++) result += base64_chars[char_array_4[i]]; i = 0; } } if (i) { for (size_t j = i; j < 3; j++) char_array_3[j] = '\0'; char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); for (size_t j = 0; j < i + 1; j++) result += base64_chars[char_array_4[j]]; while (i++ < 3) result += '='; } return result; } ```
查看原文
I asked Claude to generate a C++ implementation of a base64 encoder, and the result was nearly identical to a version on StackOverflow. I guess that wouldn’t normally be an issue, except it turns out the StackOverflow example seems to be derived from copyrighted code.<p>Stackoverflow relevant comment: https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;180947&#x2F;base64-decode-snippet-in-c#comment137345692_13935718<p>Claude version:<p>std::string base64encode(const char* data, size_t length) { static const char* base64_chars = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot; &quot;abcdefghijklmnopqrstuvwxyz&quot; &quot;0123456789+&#x2F;&quot;;<p><pre><code> std::string result; result.reserve(((length + 2) &#x2F; 3) * 4); size_t i = 0; unsigned char char_array_3[3]; unsigned char char_array_4[4]; while (length--) { char_array_3[i++] = *(data++); if (i == 3) { char_array_4[0] = (char_array_3[0] &amp; 0xfc) &gt;&gt; 2; char_array_4[1] = ((char_array_3[0] &amp; 0x03) &lt;&lt; 4) + ((char_array_3[1] &amp; 0xf0) &gt;&gt; 4); char_array_4[2] = ((char_array_3[1] &amp; 0x0f) &lt;&lt; 2) + ((char_array_3[2] &amp; 0xc0) &gt;&gt; 6); char_array_4[3] = char_array_3[2] &amp; 0x3f; for (i = 0; i &lt; 4; i++) result += base64_chars[char_array_4[i]]; i = 0; } } if (i) { for (size_t j = i; j &lt; 3; j++) char_array_3[j] = &#x27;\0&#x27;; char_array_4[0] = (char_array_3[0] &amp; 0xfc) &gt;&gt; 2; char_array_4[1] = ((char_array_3[0] &amp; 0x03) &lt;&lt; 4) + ((char_array_3[1] &amp; 0xf0) &gt;&gt; 4); char_array_4[2] = ((char_array_3[1] &amp; 0x0f) &lt;&lt; 2) + ((char_array_3[2] &amp; 0xc0) &gt;&gt; 6); for (size_t j = 0; j &lt; i + 1; j++) result += base64_chars[char_array_4[j]]; while (i++ &lt; 3) result += &#x27;=&#x27;; } return result; }</code></pre>