Brian Dunning's FileMaker Custom Functions

OK_Encrypt ( Text ; Key )

Gently encrypt text with key

  Average rating: 4.5 (31 votes) Log in to vote

Peter Vinogradov   Peter Vinogradov - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
OK_Encrypt ("Hello" ; "Goodbye" )
  Sample output:
ÔÛÐÑ

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

I'm using this to create encrypted QR codes, so it only needs to operate on small amounts of text, and it doesn't need to be totally uncrackable, just difficult.

Note: The function keeps track of its position in the text by enclosing a counter in two sets of pipes ("||"). This isn't the most elegant solution, but it fits my purposes. If you need to use pipes in your text, revise to use a different bracket, or add a counter parameter to the function.

Update: To avoid the pipes issue, please see the much better version offered in the comments below.

 

Comments

comment   comment, VR
Dec 30, 2010
> The function keeps track of its position in the text by enclosing a counter in two sets of pipes ("||"). This isn't the most elegant solution

Indeed. You could have used the length of text to determine which character of the key to apply.
 
Peter Vinogradov   Peter Vinogradov
Dec 30, 2010
@comment, VR, I'm not sure what you mean. I'm always working on the first character of "text", and then passing the rest of the text on to the next recursion, so the true length of the text is not determinable within that recursion. This aspect of recursion always gives me a toothache, so I might be overlooking the obvious. If you can email me a revised version illustrating your point, I'll be happy to post it and credit you.
 
comment   comment, VR
Dec 30, 2010
Here is one simple example (out of several possible):

Encode ( plainText ; key )

Let ( [
P = Left ( plainText ; 1 ) ;
lenP = Length ( plainText ) ;
i = Mod ( lenP - 1 ; Length ( key ) ) + 1 ;
K = Middle ( key ; i ; 1 ) ;
C = Char ( Code ( P ) + Code ( K ) )
] ;
C & Case ( lenP > 1 ; Encode ( Right ( plainText ; lenP - 1 ) ; key ) )
)
 
comment   comment, VR
Dec 30, 2010
Here is another way - this one uses a "caterpillar track" to serve up the key:

http://fmforums.com/forum/topic/68542-custom-functions-to-encrypte-export-files/page__p__325022#entry325022
 
Peter Vinogradov   Peter Vinogradov
Dec 30, 2010
OK, I see what you did. I was stuck mentally on trying to match the key against the text from beginning to end. Your way effectively lays it against the text from back to front, with the advantage that we don't need to know how many letters came before the current letter. Thanks for the improvements! And the article you linked to in your fmforums post was helpful in letting me know that (a) this basically a Vigenere cypher, and (b) cracking a Vigenere cipher is annoying enough that the encryption will meet my needs :)
 
comment   comment, VR
Dec 30, 2010
Yes, it is basically a Vernam or a Vigenere - except that technically you are supposed to do:

C = Char ( Mod ( Code ( P ) + Code ( K ) ; n )

where n is the length of the allowable alphabet.


As for strength: if you were to use random keys of at least the message length, and use each key only once, then this would be unbreakable (as long as the key remains secret).
 
Brian Donovan   Brian Donovan, Mexico
Feb 21, 2015
Very nice code I love it! congratulations, but I have some comments:


For long text (20 words or more) its very slow

if the encryption key has the next shift_alt values it will not work ˜ˆ ...you can add some code to not allow this, but I thing this should be fixed in the formula!

if the key is “r” or “rr” or “rrrrrrrrrrrrrr” the encryption is the same! actually lots of combinations can be the same key

You can know if the encrypted text was encrypted with only numbers just by looking at it ...if you have some knowledge of this formula.


for some reason I don't know the formula stops working I had to close and open the file again (FileMaker 11).


Hope this helps! I still think this is the best encryption formula in this site! :)



Brian
 
Brian Donovan   Brian Donovan, Mexico
Feb 21, 2015
Forgot one comment:

The text to encrypt defenetly can't have any shift_alt values!


Brian
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: