Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6620 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I need to have to calculate a key that's quite long if I simply concat the values. Moreover That key will be twice as long since I need to add another long key.

The length of the key is unknown. Each element of the key are numbers.

Key 1 :12 52 56 89 56 566 565 144 12 533

Key 2 :) 56 98 654 23 7896 52 12 562 4566

I'd like to convert to transform Key1 and key2 in kind of checksum : one unique number.

So I'd have

Cheksum key 1 : 4665665

Cheksume key 2 : 895965

Moreover, I want the "Cheksum" key to be equal regardless of the order of the elements

Key 1 :12 52 56 89 56 566 565 144 12 533 Cksum = 4665665

Key 1 :12 533 56 566 56 89 565 144 12 52 Cksum = 4665665

Of course in my example the numbers are completly bogus, and what I call cheksum isn't really a cheksum as chesum prist will call it.

What I need is a mathematical calculation thats transforms a string of number regarless of their order in a unique number.

Posted

It would be helpful to know the purpose of this. Unless you place some limits on the quantity and size of the numbers in a key, you are very likely to exceed the capacity of Filemaker's calc engine. And there's no way that your checksum will be shorter than the key and still be unique. Quite the contrary: because the checksum needs to represent any combination of its elements, it will be considerably larger.

Posted (edited)

Yes I wanted something smaller than the conatened key.

I think FM 8 as ha limit for the key comparison (I don't knwo how many), plus I wanted, with a smaller key to ease the comparison.

I'm not sure that the cheksum would be larger, for instance MD5 cheksum that validates files has 32 characters length only, and that works for Gigabytes files.

So, provided it's only numbers in my key, it should be much smaller than that and much simpler.

Perhaps there's a mathematical theoreme somewhere that allows to have a unique result for a string of numbers.

P.S :) The purpose of this is a multikey relationship with exact matching.

Unfortunately for my purpose, a multikey matches any result contained in it. I want 2 multikey to match exactly, but I have to flatten them to do so (I think), hence my string of numbers

Edited by Guest
Posted

Ray Cologon of Nightwing (www.nightwing.com) has posted 2 different checksum algorithisms on his site. I modified one of the methods and created 2 CFs to do the calcs. Check his site and see if they are what you need.

Steve

Posted (edited)

Thanks for the correction Laretta. My functions are a straight lift (and are attributable to) Ray Cologon. I made no change at all, and since they were written for Version 6 (or earlier), they could be shortened significantly in Version 8. Although not elegant, they work just fine.

Version 8 (and probably version 7) have very large field capacities:

Number

Supports values up to 800 digits or other characters, and the negative values of the same range. Index is based on the first 400 significant digits.

The above is straight out of Filemaker Help.

If you'd like, I'll publish both functions.

Steve

Edited by Guest
Posted

for instance MD5 cheksum that validates files has 32 characters length only, and that works for Gigabytes files.

... but it isn't guaranteed to be unique. It can't be. There is only a probability that you won't get duplicates.

Posted

MD5 checksum IS smaller than its source. But it is not unique - it's only "statistically unique".

It's a simple math: if the source has 9 numeric characters, there are one million possible combinations. If the checksum is to be unique for each one of those, there must be one million possible checksums. If the checksum is to have a fixed length, it MUST be at least 9 characters.

I believe that mathematically the shortest string that will be truly unique to your key, in any order, is your key after sorting.

There are ways to shorten the result 'cosmetically'. If you convert the numbers to a higher base, you will get fewer characters. But beyond that I think would require placing some limits on the numbers in the key. To take a rather extreme example, if a number in your key could only be either 0 or 1, we could - since the order is to be ignored - make the checksum "so many zeros and so many ones" (a.k.a run-length coding in data compression).

Posted (edited)

Okay, the 1st one calculates the checksum:

/* This was originated by Ray Cologon of Nightwing Enterprises

CF: Checksum

Input

*/

Case(

IsEmpty(Input); "";

not (Length(Input) = Length(GetAsNumber(Input))); "-error-";

Input &

Right(10 - Mod(Case(Right(Input; 1) = 0; 0; Mod(Right(Input; 1) * 2; 9); Mod(Right(Input; 1) * 2; 9); 9) +

Case(Length(Input) > 1; Middle(Input; Length(Input) - 1; 1)) +

Case(Length(Input) > 2; Case(Middle(Input; Length(Input) - 2; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 2; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 2; 1) * 2; 9); 9)) +

Case(Length(Input) > 3; Middle(Input; Length(Input) - 3; 1)) +

Case(Length(Input) > 4; Case(Middle(Input; Length(Input) - 4; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 4; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 4; 1) * 2; 9); 9)) +

Case(Length(Input) > 5; Middle(Input; Length(Input) - 5; 1)) +

Case(Length(Input) > 6; Case(Middle(Input; Length(Input) - 6; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 6; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 6; 1) * 2; 9); 9)) +

Case(Length(Input) > 7; Middle(Input; Length(Input) - 7; 1)) +

Case(Length(Input) > 8; Case(Middle(Input; Length(Input) - 8; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 8; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 8; 1) * 2; 9); 9)) +

Case(Length(Input) > 9; Middle(Input; Length(Input) - 9; 1)) +

Case(Length(Input) > 10; Case(Middle(Input; Length(Input) - 10; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 10; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 10; 1) * 2; 9); 9)) +

Case(Length(Input) > 11; Middle(Input; Length(Input) - 11; 1)) +

Case(Length(Input) > 12; Case(Middle(Input; Length(Input) - 12; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 12; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 12; 1) * 2; 9); 9)) +

Case(Length(Input) > 13; Middle(Input; Length(Input) - 13; 1)) +

Case(Length(Input) > 14; Case(Middle(Input; Length(Input) - 14; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 14; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 14; 1) * 2; 9); 9)) +

Case(Length(Input) > 15; Middle(Input; Length(Input) - 15; 1)) +

Case(Length(Input) > 16; Case(Middle(Input; Length(Input) - 16; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 16; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 16; 1) * 2; 9); 9)) +

Case(Length(Input) > 17; Middle(Input; Length(Input) - 17; 1)) +

Case(Length(Input) > 18; Case(Middle(Input; Length(Input) - 18; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 18; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 18; 1) * 2; 9); 9)) +

Case(Length(Input) > 19; Middle(Input; Length(Input) - 19; 1)) +

Case(Length(Input) > 20; Case(Middle(Input; Length(Input) - 20; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 20; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 20; 1) * 2; 9); 9)) +

Case(Length(Input) > 21; Middle(Input; Length(Input) - 21; 1)) +

Case(Length(Input) > 22; Case(Middle(Input; Length(Input) - 22; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 22; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 22; 1) * 2; 9); 9)) +

Case(Length(Input) > 23; Middle(Input; Length(Input) - 23; 1)) +

Case(Length(Input) > 24; Case(Middle(Input; Length(Input) - 24; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 24; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 24; 1) * 2; 9); 9)) +

Case(Length(Input) > 25; Middle(Input; Length(Input) - 25; 1)) +

Case(Length(Input) > 26; Case(Middle(Input; Length(Input) - 26; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 26; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 26; 1) * 2; 9); 9)) +

Case(Length(Input) > 27; Middle(Input; Length(Input) - 27; 1)) +

Case(Length(Input) > 28; Case(Middle(Input; Length(Input) - 28; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 28; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 28; 1) * 2; 9); 9)) +

Case(Length(Input) > 29; Middle(Input; Length(Input) - 29; 1)) +

Case(Length(Input) > 30; Case(Middle(Input; Length(Input) - 30; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 30; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 30; 1) * 2; 9); 9)) +

Case(Length(Input) > 31; Middle(Input; Length(Input) - 31; 1)) +

Case(Length(Input) > 32; Case(Middle(Input; Length(Input) - 32; 1) = 0; 0; Mod(Middle(Input; Length(Input) - 32; 1) * 2; 9); Mod(Middle(Input; Length(Input) - 32; 1) * 2; 9); 9)); 10); 1))

This one validates the checksum:

/* This was originated by Ray Cologon of Nightwing Enterprises

CF: ValidateChecksum

Input

*/

Case(IsEmpty(Input); ""; Exact(

Right(10 - Mod(Case(Right(Left(Input; Length(Input) - 1); 1) = 0; 0; Mod(Right(Left(Input; Length(Input) - 1); 1) * 2; 9); Mod(Right(Left(Input; Length(Input) - 1); 1) * 2; 9); 9) +

Case((Length(Input) - 1) > 1; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 1; 1)) +

Case((Length(Input) - 1) > 2; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 2; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 2; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 2; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 3; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 3; 1)) +

Case((Length(Input) - 1) > 4; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 4; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 4; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 4; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 5; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 5; 1)) +

Case((Length(Input) - 1) > 6; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 6; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 6; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 6; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 7; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 7; 1)) +

Case((Length(Input) - 1) > 8; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 8; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 8; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 8; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 9; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 9; 1)) +

Case((Length(Input) - 1) > 10; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 10; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 10; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 10; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 11; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 11; 1)) +

Case((Length(Input) - 1) > 12; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 12; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 12; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 12; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 13; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 13; 1)) +

Case((Length(Input) - 1) > 14; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 14; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 14; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 14; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 15; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 15; 1)) +

Case((Length(Input) - 1) > 16; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 16; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 16; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 16; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 17; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 17; 1)) +

Case((Length(Input) - 1) > 18; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 18; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 18; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 18; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 19; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 19; 1)) +

Case((Length(Input) - 1) > 20; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 20; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 20; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 20; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 21; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 21; 1)) +

Case((Length(Input) - 1) > 22; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 22; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 22; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 22; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 23; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 23; 1)) +

Case((Length(Input) - 1) > 24; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 24; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 24; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 24; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 25; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 25; 1)) +

Case((Length(Input) - 1) > 26; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 26; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 26; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 26; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 27; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 27; 1)) +

Case((Length(Input) - 1) > 28; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 28; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 28; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 28; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 29; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 29; 1)) +

Case((Length(Input) - 1) > 30; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 30; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 30; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 30; 1) * 2; 9); 9)) +

Case((Length(Input) - 1) > 31; Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 31; 1)) +

Case((Length(Input) - 1) > 32; Case(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 32; 1) = 0; 0; Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 32; 1) * 2; 9); Mod(Middle(Left(Input; Length(Input) - 1); (Length(Input) - 1) - 32; 1) * 2; 9); 9)); 10); 1); Right(Input; 1)); "Valid"; "ERROR")

Copy and paste the comments as part of each CF. The function name starts after 'CF', the next line has the name of the 1st (and only paramter).

Steve

Edited by Guest

This topic is 6620 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.