Wikipedia:Reference desk/Archives/Computing/2021 July 9

= July 9 =

Section tag
hello, please what is the function of this tool   ?--طلال (talk) 03:10, 9 July 2021 (UTC)
 * The code allows part of a page to be included into others. The code above marks the start of the part and there should be matching  further down the page. See Help:Labeled section transclusion — GhostInTheMachine talk to me 14:26, 9 July 2021 (UTC)

Arbitrary hard computationally problem?
We know that there are NP-hard problem and some applications as sha-256, but for all of the applications, there is a fixed amount of computation (even if extremely large), needed to solve them. It is clear that if you take 10 different sha-256 string, the amount of computation needed to solve each of the string will be multiplied by 10 (though it can be parallelized, so in so some sense it might haven't changed at all). 1)let m be an arbitrary natural number. Can an algorithm exist, so the complexity ratio between calculating the challenge (for example hashing the string), to solving the challenge (for example find the original string) will be proportion to m without increasing the calculating the challenge complexity? I think the answer is true if we only dealing with hashing, as one my just toss a random string and define the hashed password as 1 million hashing calculation . But this leads to a different problem, the validation complexity is proportional to m. Furthermore, It is not clear, if 2) one can make an asymmetricity like in public private keys protocol. Does anyone have idea regarding this questions? --Exx8 (talk) 10:38, 9 July 2021 (UTC)


 * Is $m$ meant to stand for the size of the input of a computational problem? If the effort needed to solve the problem is proportional to the size of the input, its complexity is obviously polynomial, so I think you mean something else. It is also not clear to me what "increasing the calculating the challenge complexity" means. I also have a problem understanding the meaning of "one my just toss a random string and define the hashed password as 1 million hashing calculation". (If you use Google translate to translate what you wrote into your native language, does it make sense to you?) --Lambiam 12:16, 9 July 2021 (UTC)

1)m stand for arbitrary complexity factor. the complexity of the algorithm to solve will be O(2^mn) for example. for example in NP problems, one can verify a solution polynomially, but find one exponentially (as far we know to this date). the idea here is to add flexibility to the algorithm: that it is complexity between solving the problem will be determent arbitrarily. Meaning you will be able to make a challenge as hard as you want, not depending only the m factor. 2)"increasing the calculating the challenge complexity" means that one might just decide to harden the challenge without paying extra complexity of calculating the challenge. for example that for any n the complexity of calculating the hashing will be constant regardless the factor constant, while unhashing (calculating the matched string) will be as hard at least as (O(2^(mn)). 3)sorry me the auto correct has replaced "might" with my. is now the sentence make sense? one might just toss a random string and define the hashed password as 1 million hashing calculation--Exx8 (talk) 16:19, 10 July 2021 (UTC)

C++, Adding an int to a string
I was very sleepy and writing code. I had a function write_file that took a string str and would write data to a file with a name "name. .ext". I needed to append an integer i to str and wanted write_file(str + to_string(i)), but I wrote write_file(str + i). It ran fine, but there were no files where they should be. It occurred to me that I'm not sure what object you end up with when you add an int to a string, and, more so, why the program didn't through a fit. More importantly, did it write files somewhere weird? I'm not a programmer (math person that needs to run simulations on a bunch of data), so apologies if this is a bit weird of a post. Thank you for any help.2601:547:1:4EE0:F463:8DEA:5A4E:B34C (talk) 11:11, 9 July 2021 (UTC)


 * The "path" argument of &thinsp;write_file&thinsp; is basically a pointer to a character array. A path such as "nonprecious.txt" is actually a pointer to an array of 16 bytes (one extra because it is a null-terminated string). Adding the value 3 to the pointer means skipping the first three bytes. So &thinsp;write_file("nonprecious.txt" + 3, data); has the same effect as &thinsp;write_file("precious.txt", data);, so a precious file may be unintentionally overwritten. If the integer added exceeds the length of the string, the result of the addition is a pointer to somewhere in memory outside the array, which can contain any random data that happens to be hanging around. Check for any recently created files with strange (possibly unprintable) names. --Lambiam 11:53, 9 July 2021 (UTC)


 * Thank you so much! When I tested the result by printing to console, nothing was there (the int was greater than str's length); which left me a bit worried that it was something like you describe. Though, since all files end up in the same place, the path gets attached to the start of str in write_file; so write_file(str) should write to, say, /directory/prefix. .ext; so, as a follow up, if str + int is junk, would it still end up writing to somewhere in /directory and have a the ".ext" extension attached? In other words, if int is larger than the string length and I pass str + int, would this be the same as passing random junk into the write_file function?2601:547:1:4EE0:F463:8DEA:5A4E:B34C (talk) 12:33, 9 July 2021 (UTC)
 * I see forward slashes, so apparently you are not using Microsoft Windows. I do not know how the function &thinsp;write_file&thinsp; is implemented in the file I/O library you are using, but a decent implementation should actually start by checking that the filename (after expansion with the current path and any default extensions) is the pathname of a file that is open for writing, which a random filename should obviously not be. So it is strange that the program execution did not abort. --Lambiam 16:36, 9 July 2021 (UTC)


 * In C++, a string can be either a C-style character array as Lambiam describes, or it may be a std::string. It's not clear from your description which you have, but since you were expecting the + operator to append to the string, it seems you have a std::string rather than a char array? On the other hand, adding an int to a std::string will indeed generate a compiler error, so I'm unclear what your code actually looks like. It's also not clear if write_file is a function you wrote or if it comes from a library; it would be helpful to post your actual code. In regards to your last question, appending junk to a path will generally indeed refer to a junk-named file in that directory, although there are cases where this won't happen (eg. if the junk contains a slash, it will refer to some (possibly nonexistent) subdirectory, or if the junk contains a "/../", it may write to a file in the parent directory, and so on). CodeTalker (talk) 20:22, 9 July 2021 (UTC)

Not sure if this helps, but you can define a fairly simple function to handle arbitrary type conversions:

Example usage:

Earl of Arundel (talk) 22:22, 9 July 2021 (UTC)