Decrypt - page 3

 

Since this thread, I have needed to do something similar i.e. lock an EA to an account and have an expiry date which is potentially different for every user without going down the DLL route.

The approach I took was:

The EA runs (a part of) the account number through CryptEncode. It pops up on the screen and the User hands it over to get their activation key.

You have a script which takes this encoded account number (supplied by the User), tags a date on the end and encrypted it again. This becomes the activation key that is sent back to the User.

The User enters the activation key as an input setting.

The EA decrypts the activation key back into an encrypted account number with a date tagged on the end. It checks that (1) the encrypted account number matches the current account number, and (2) that the expiry date has not passed.

This process could be simplified further if you don't want to lock the EA to a specific account. 

Hope that helps someone

 
Andrew Sumner:

I know this is an old thread, but I recently came across as the same question Gordon was asking here.  Yes it is possible to reverse the output of ArrayToHex.  Here's my (very inelegant) solution.  It should print two identical copies of the string to the Experts log.  I'm sure there's a better way to perform the actions my HexToDecimal function's doing, but hey it was written at 2am :)

...

bool HexToArray(string str, uchar &arr[])

{
   int arrcount = ArraySize(arr);
   int strcount = StringLen(str);
   if (arrcount < strcount / 2) return false;
  
   int i=0, j=0;
  
   for (i=0; i<strcount; i+=2)
   {
      string sub = StringSubstr(str, i, 2);
      uchar tmpchr = HexToDecimal(StringSubstr(str, i, 1))*16 + HexToDecimal(StringSubstr(str, i+1, 1));    
      arr[j] = tmpchr;
      j++;
   }
  
   return true;
}

Just for fun. Here is my version, more than 10 times faster :-)

#define HEXCHAR_TO_DECCHAR(h)  (h<=57 ? (h-48) : (h-55))
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool HexToArray2(string str,uchar &arr[])
  {
   int strcount = StringLen(str);
   int arrcount = ArraySize(arr);
   if(arrcount < strcount / 2) return false;

   uchar tc[];
   StringToCharArray(str,tc);

   int i=0, j=0;
   for(i=0; i<strcount; i+=2)
     {
      uchar tmpchr=(HEXCHAR_TO_DECCHAR(tc[i])<<4)+HEXCHAR_TO_DECCHAR(tc[i+1]);
      arr[j]=tmpchr;
      j++;
     }

   return true;
  }
HexToArray 33 1000 135 768 68.77%
HexToArray2 38 1000 11 968 6.06%
 
Alain Verleyen:

Just for fun. Here is my version, more than 10 times faster :-)












Thanks!  I knew my version was clunky, was hoping someone would come up with a better solution :)