Changeset 2715


Ignore:
Timestamp:
Feb 17, 2011, 4:47:40 PM (11 years ago)
Author:
Sven Rech
Message:

RegEx CostFunction has more increments now (OpenCL untested)

Location:
trunk/CrypPlugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/AES/AES.cs

    r2670 r2715  
    534534            opencl = opencl.Replace("$$BITS$$", "" + bits);
    535535
    536             string decryptionCode = "";
     536            string decryptionCode = string.Format("int decryptionLength = {0}; \n", decryptionLength);
    537537            int blocks = decryptionLength / 16;
    538538            if (blocks >= 1)
  • trunk/CrypPlugins/CostFunction/CostFunction.cs

    r2334 r2715  
    425425            try
    426426            {
    427                 bool match = regularexpression.Matches(input);
    428                 if (match)
    429                 {
    430                     return 1.0;
    431                 }
    432                 else
    433                 {
    434                     return -1.0;
    435                 }
     427                return regularexpression.MatchesValue(input);
    436428            }
    437429            catch (Exception e)
    438430            {
    439431                GuiLogMessage(e.Message, NotificationLevel.Error);
    440                 return -1.0;
     432                return Double.NegativeInfinity;
    441433            }
    442434
  • trunk/CrypPlugins/CostFunction/RegEx.cs

    r2086 r2715  
    110110
    111111            //initialization code:
    112             code = code.Replace("$$COSTFUNCTIONINITIALIZE$$", string.Format("int state = {0}; \n", startIndex));
     112            code = code.Replace("$$COSTFUNCTIONINITIALIZE$$", string.Format("int state = {0}; \n int count = 0; \n", startIndex));
    113113
    114114            //calculation code:
    115115            code = code.Replace("$$COSTFUNCTIONCALCULATE$$", "int absState = ((state >= 0) ? state : ~state); \n"
    116116                + "state = transitionMatrix[absState*256+c]; \n"
    117                 + "if (state == NOTRANSITION) { results[x] = -1.0f; return;} \n");
     117                + "if (state == NOTRANSITION) { results[x] = (float)(-decryptionLength + count); return;} \n count++; \n");
    118118
    119119            //result calculation code:
    120             code = code.Replace("$$COSTFUNCTIONRESULTCALCULATION$$", "if (state < 0) result = 1.0f; else result = -1.0f;");
     120            code = code.Replace("$$COSTFUNCTIONRESULTCALCULATION$$", "if (state < 0) result = 1.0f; else result = 0.0f;");
    121121
    122122            return code;
     
    144144
    145145            return (state < 0);
     146        }
     147
     148        /// <summary>
     149        /// Matches input with the given regex and returns a value which indicates "how much" it matches.
     150        /// </summary>
     151        /// <param name="input"></param>
     152        /// <returns></returns>
     153        public int MatchesValue(byte[] input)
     154        {
     155            if (transitionMatrix == null)
     156                return Int32.MinValue;
     157
     158            int state = startIndex;
     159            int count = 0;
     160
     161            foreach (byte i in input)
     162            {
     163                int absState = state >= 0 ? state : ~state;
     164                state = transitionMatrix[absState][i];
     165                if (state == NOTRANSITION)
     166                    return (-input.Length + count);
     167                count++;
     168            }
     169
     170            return (state < 0) ? 1 : 0;
    146171        }
    147172
Note: See TracChangeset for help on using the changeset viewer.