AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Free pascal tstrings.addstrings3/17/2023 ![]() From the implementation of calcBl, if keyStr is empty, your result will be 0. You have the following code: //calculating block length 2.6 So if the next character in memory happens to be #0, you will be doing exactly as described above.Īdditional problem.Your inner loop ( for posB := 1 to bl do) will read beyond the length of inStr on the last iteration of the outer loop.Suppose you have a 5 character string, and key that produces block length 2.With the additional source code, my hunch is confirmed: When your input string has an odd number of characters: your algorithm (which relies on pairs of characters) adds an extra character with value #0.You are always processing 1 too many characters with the extra character being #0.So it's quite probable that you have at least one of the following 2 bugs in your code: Declaration: procedure AddStrings(TheStrings: TStrings) Virtual. This could very well cause the "strange behaviour" you're seeing. Free Pascal version 2.2.2: Reference guide for RTL units. ![]() The reason for my hunch is that #0 is a valid character in a string: but whenever that string needs to be processed as PChar, #0 will be interpreted as a string terminator. ![]() Try the following code and see if you have a similar experience with S3: S1 := 'a'#0 So without the relevant information, I can only guess I do think I have a good hunch though. The irony is that you have all the information at your fingertips to provide a small concise demonstration of your problem - including sample input and expected output. You haven't even been clear about where you're seeing the shortened Result: GUI Control/Debugger/Writeln Azure Ad B2c Visual Studio Notifications Editor Hash Webgl Optimization Core Compiler Construction Phpstorm Artifactory Grep Tfs Fiware Rss Razor Three.js Qt4 Kibana Character Encoding Jquery Ui Memory Management Windows Phone 8 Blockchain Msbuild Airflow Opencv Silverstripe Asp.net Mvc 4 Puppet Cmake Karate Ajax Ssh Microservices Com. However, your deliberate efforts to hide the relevant code mean that we're really shooting in the dark. I am 99.99% certain that your problem is due to a subtle bug in your code. adding the block in front of the existing result stringĪfter all the loops "result" has the right value, but in the last step (between "result := block + temp" and the "end " of the function) "block" replaces the content of "result" with itself completely, it doesn't add result at the end anymore.Īnd as you can see I even used a temp variable to try to work around that. filling block with chars starting from back of virtual block (in inStr) Result := (result + ord(keyStr)) mod 5 įunction rotation(inStr,keyStr:string):string If (i1 mod i2) 0 then result := (i1 div i2) else result := (i1 div i2) - 1 amount of blocksįunction amBl(i1:integer i2:integer):integer Several other functions that are used for "rotation" are above. But when i try to reverse the order it just gives me the the last "block". When I add the result first and then the block it works fine and gives me back the original string. I add two strings, in this case appending the result string to the current "block" string and making that the result. "He|ll|o " becomes "o |ll|He" (block length of 2). This one should blockwise reverse the input. The program has several "encryption" algorithms. ![]()
0 Comments
Read More
Leave a Reply. |