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

Custom Functions to encrypte export files


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

Recommended Posts

Posted

I have a need to encrypt some data that will be exported to a file then imported to another database and decrypted. I wrote a set of custom functions that seem to work well but would love someone to try to break it. I know i could probably do it with less functions but I dont mind using 4 for readability. for my solution having the key hard coded into the functions works fine because it wont be exported with the data.

here is some sample input.

now is the time for all good men to come to the aid of the party

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.

~!@#$%^&*()_+{}|][":';?>,/*-+1234567890

sample>

´Øã¶ÔÙÚµã»ÜÈÙµÛƹÍÌá¿Ö¿ÔÑçµÏÔºÆÙápæ×·ÄÔ×fØÒÁÉÐâ±äãË|·³¸fºÁ®¬§Äɽrµ²Ã¾¹µ¥´ÈĦ·¨¿ÃÅ°²]ðÑl¬æâî¬ÏÊt©¦²¥y¤¢¤¢«

Sample>

now is the time for all good men to come to the aid of the party

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.

~!@#$%^&*()_+{}|][":';?>,/*-+1234567890

Sample>

Here are the 4 custom functions

encrypt(text)

Let([

$Key = "FileMakerProRocks";

$TextLen = Length(text);

$KeyLen = Length($Key)];

EncryptLoop ( text ; $key ; 1 ; 1 ; $keyLen ; $TextLen ; "" ))

EncryptLoop ( text ; key ; k ; n ; keyLen ; TextLen ; Outword )

Let([

$TextNum=Code (Middle (Text ; k ; 1 ));

$KeyNum=Code (Middle (Key ; n ; 1 ));

$Result = $TextNum + $KeyNum;

$Result = If($Result > 255;$Result-255;$Result);

$NewChar = Char ( $Result );

$Outword = OutWord & $NewChar;

$k=k+1;

$n=If(n>keylen-1;1;n+1)];

If($k>TextLen;$outword;EncryptLoop(Text;Key;$k;$n;KeyLen;TextLen;$outWord)))

Decrypt(test)

Let([

$key = "FileMakerProRocks";

$TextLen = Length(text);

$KeyLen = Length($Key)];

DecryptLoop ( text ; $key ; 1 ; 1 ; $keyLen ; $TextLen ; "" ))

DecryptLoop ( text ; key ; k ; n ; keyLen ; TextLen ; Outword )

Let([

$TextNum=Code (Middle (Text ; k ; 1 ));

$KeyNum=Code (Middle (Key ; n ; 1 ));

$Result = $TextNum - $KeyNum;

$Result = If($Result <0;$Result+255;$Result);

$NewChar = Char ( $Result );

$Outword = OutWord & $NewChar;

$k=k+1;

$n=If(n>keylen-1;1;n+1)];

If($k>TextLen;$outword;DecryptLoop(Text;Key;$k;$n;KeyLen;TextLen;$outWord)))

It uses nested loops to change the text 1 characters at a time up or down the characters table based on the key. once it runs out of key characters it starts over at the beginning of the key.

I have tried to send it every characters on the keyboard but I am still Leary someone will send it something that will mess it up.

Thanks

Posted

Well, it's kind of ironic because it doesn't do that, and as a result your code doesn't break where it should - that is, when the input is NOT within the ASCII alphabet. For example:

Plain text = "≤"

Key = "s"

Code ( "≤" ) + Code ( "s" ) = 8919

and Char ( 8919 - 255 ) is definitely not within the 255 limit of ASCII.

If you want to limit the output (and consequently, the input) to ASCII characters only, you should use the Mod() function.

NOTE:

1. You didn't ask, but I believe it needs to be stated for the benefit of other readers: this is NOT a very secure encryption, particularly so if the key is going to be fixed - see:

http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher

2. I would roll your 4 functions into one:

Vigenere ( text, key, decode )


Let ( [

tChar = Left ( text ; 1 ) ; 

kChar = Left ( key ; 1 ) ;

tLen = Length ( text ) ; 

kLen = Length ( key ) 

] ;

Char ( Mod ( Code ( tChar ) + Code ( kChar ) * ( not decode - decode ) ; 255 ) )

&

Case ( tLen > 1 ; Vigenere ( Right ( text ; tLen - 1 ) ; Right ( key ; kLen - 1 ) & kChar ; decode ) )

)

The text parameter is either plaintext or ciphertext. The function encodes by default, and decodes when decode returns true.

Posted

Thank you, that was in interesting article. I think for what Im doing it will be fine as none of the data is very sensitive. I have installed your function and will play with it, seems alot cleaner than mine. I will still probably put the key in the function because the data will always be decrypted while in the database so having the key present is not an issue as there is nothing to decrypt.

What I'm trying to do here and I think it will work out is to have a host file push out updates for others via an FTP site. The client systems can then access these files via a website or also an ftp site. Ultimately I would like to export an xml file to a temp directory on the host, take the file as a whole, encrypt it, up load it to the ftp sites where the clients will download decrypt and import. Because there will be several tables that get updated in this manner there will also be a kind of control table that gets pushed out that will hold serial number keys to let the clients know when there is an update for any particular table.

Posted

I'm not sure why it would be but the all in one function is noticeable slower than the 4 function system like by 3 or 4 times. seems like it does the same thing. In fact using the same key i can encrypt using one and decrypt using the other

Posted

Well, for heavy use the all-in-one may not be a good idea, since the decision whether to encode or decode is repeated for each individual character.

Another thing that might help speed it up a bit is to make it tail-recursive, e.g.:

VigenereEncode ( plaintext, key, output )


Let ( [

pChar = Left ( plaintext ; 1 ) ; 

kChar = Left ( key ; 1 ) ;

pLen = Length ( plaintext ) ; 

kLen = Length ( key ) ; 

n = Code ( pChar ) + Code ( kChar )

] ;

Case ( 

pLen > 1 ; 

VigenereEncode ( Right ( plaintext ; pLen - 1 ) ; Right ( key ; kLen - 1 ) & kChar ; output & Char ( Mod ( n ; 128 ) ) ) ;

output 

)



)

This topic is 5543 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.