Author Topic: function MD5(const Str: string): string;  (Read 1940 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
function MD5(const Str: string): string;
« on: September 17, 2008, 03:50:02 pm »
Function Name: MD5
Script Description: Basically sense I had issues using MD5String before, this tries to get a correct value out of it
Original Author: Curt (DorkeyDear)
Core Version: 2.2 (Server v2.6.3)
Code:
Code: [Select]
function MD5(const Str: string): string;
var
  i: byte;
begin
  while (true) do begin
    Result := MD5String(Str);
    for i := 0 to 11 do begin
      if (Result <> MD5String(Str)) then begin
        i := 0;
        break;
      end;
    end;
    if (i > 0) then break;
  end;
end;

Offline zop

  • Major
  • *
  • Posts: 81
Re: function MD5(const Str: string): string;
« Reply #1 on: September 17, 2008, 07:14:39 pm »
hmm?
Code: [Select]
while (true) do begin
    Result := MD5String(Str);
    for i := 0 to 11 do begin
      if (Result <> MD5String(Str)) then begin
.........
You already give "Result := MD5String(Str)",so "if (Result <> MD5String(Str))"  will never happen right?
And then if this is what you want then
Code: [Select]
for i := 0 to 11 do begin
      if (Result <> MD5String(Str)) then begin
        i := 0;
        break;
The "i" will always 0. Is it a always loop code?
« Last Edit: September 17, 2008, 07:17:08 pm by zop »

http://122.116.167.31:23238:23238/galavela/?inc=player&name=%5BTomato+Bird%5D+Cibo[/size=1]

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: function MD5(const Str: string): string;
« Reply #2 on: September 17, 2008, 11:36:17 pm »
He's doing this because evidently MD5String doesn't always respond with the same info... could be wrong though (correct me please).

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: function MD5(const Str: string): string;
« Reply #3 on: September 18, 2008, 05:34:57 am »
iDante is correct, i had issues with it before, so I created this

It does 12 checks, if any of them are different than the first set value of it, it will reset the return value and start the checks over

I probably could have made it with repeat until statement to make it slightly shorter, but it doesn't matter that much.

Code: [Select]
function MD5(const Str: string): string;
var
  i: byte;
begin
  repeat
    Result := MD5String(Str);
    for i := 0 to 11 do begin
      if (Result <> MD5String(Str)) then begin
        i := 0;
        break;
      end;
    end;
  until (i > 0);
end;
but untested, don't use repeat statement often, could be wrong
actually this may also work with a while (i > 0) sense i starts at 0, but wouldn't in other languages that don't initially set the value of numbers..

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: function MD5(const Str: string): string;
« Reply #4 on: September 19, 2008, 01:15:40 pm »
Code: [Select]
while not regexpmatch('^[0-9a-f]{32}$',result) do
  result := md5string(str);

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: function MD5(const Str: string): string;
« Reply #5 on: September 19, 2008, 09:24:30 pm »
Code: [Select]
while not regexpmatch('^[0-9a-f]{32}$',result) do
  result := md5string(str);
Nice thinking, didnt even think about that... although wouldn't it be possible for the "random" error to modify one of the 32 characters to be an invalid allowed character?

but then again i guess mine isn't perfect.. if x amount of the same error occurs in a row :P then it'll recognize it as correct, heh.
« Last Edit: September 19, 2008, 09:30:07 pm by DorkeyDear »

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: function MD5(const Str: string): string;
« Reply #6 on: September 20, 2008, 04:39:33 am »
but then again i guess mine isn't perfect.. if x amount of the same error occurs in a row :P then it'll recognize it as correct, heh.
yup, you can never be sure about that. Also it seems to be rare enough to be cared about.

And the while loop with a regex can hang your server if the error occurs too much, but it'd already mean that something is really wrong with the server so it doesnt matter either ;)

Offline Rampage_Terranius

  • Major
  • *
  • Posts: 69
  • The Strategist
    • Soldat Noob Servers
Re: function MD5(const Str: string): string;
« Reply #7 on: September 22, 2008, 11:43:03 am »
yeah ive had problems with md5string adding extra letters or only coming back with just half the encryption before