Results 1 to 10 of 16

Thread: String handling issue with Free Pascal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by SilverWarior View Post
    Hi Sogcelak!

    You are on the right track with your approach but you only forgot one thing. You should pre-set the string lenght before changing its idividual characters using SetLenght method (http://www.freepascal.org/docs-html/...setlength.html).

    Do mind that if you wanna create all posible strings first you would need quite a lot of memory (NumberOfPosibleCharacters exponeted to StringLenght multiplied by 1 byte if using AnsiString or 2 byte if using WideChar (Unicode).
    So having 23 posible chars (english alphabet) and strings with 12 characters lenght you would require you to have 19931.234812266 TB of memory.
    So you might wanna create them on demmand:
    1. Create a string you wish to test
    2. Create MD5 hash of that string
    3. Compare generaed hash with input hash
    4. Free up a string or reuse it for generating next test string.
    5. Repeat until you find result or iterate through all posible strings.

    Also do note that this is posible for same MD5 hash string to be generated from different data source even if the size of data sources matches. So you would need to test every posible string.
    For your last statement, I'm very well aware of that. That's why I want to store the matches to be able to list all of them, because there can be more.

    And for the memory issue, this is exactly my problem why I can't store these in a file or something like that. It would maket it super easy, but instead I need to rewrite the same string over and over again to avoid stack overflows, and Pascal doesn't like the idea that the string's length might also be changed in the process, and I'm still searching for a counter. A recursive approach would also work, because then with a character length of 12, only 12 strings would be in the memory at a single time, but unfortunately I couldn't come up with a working recursive code for this problem.

  2. #2
    Quote Originally Posted by Sogcelak View Post
    And for the memory issue, this is exactly my problem why I can't store these in a file or something like that.
    Go and read my post again. I made you a caclulation in order to show how much memory or HDD space you would require in order to save all posible string variations if you have string 12 character long and there can be 23 posible characters. Even if you go and save that to your hard drive I doubt you have computer with almost 20000 terabytes of hard drive space.

    Quote Originally Posted by Sogcelak View Post
    and Pascal doesn't like the idea that the string's length might also be changed in the process, and I'm still searching for a counter.
    Pascal doesen't have any problems when you change string size. Simply use the function I proposed.

    Quote Originally Posted by Sogcelak View Post
    A recursive approach would also work, because then with a character length of 12, only 12 strings would be in the memory at a single time, but unfortunately I couldn't come up with a working recursive code for this problem.
    How did you come up to that? Why do you think you would need 12 strings in your memory?
    The number of strings in your memory could only be affected by the number of concurent processes you intent touse (multithreading).
    For recursive approach you only need one string stored in the memory at any time. The only thing is that this string gets updated every time before MD5 has is generated from it.

  3. #3
    Thanks for the links guys. I will look at them. Especially the Free Pascal one, since that's what I'm using.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •