///<summary>The result of applying this hash function to the given data, by interpreting the operations in the inner loop.</summary> public int Interpret(IntStream data) { // copy initial state var state = InitialState.ToArray(); var buffer = new int[1 << 12]; while (true) { var n = data.Read(buffer); if (n == 0) break; // feed data through the state via custom steps for (var i = 0; i < n; i++) { // input into hash via first state variable state[0] = buffer[i]; // apply custom hashing steps foreach (var step in Steps) { // read var lhs = state[step.LeftInputIndex]; var rhs = state[step.RightInputIndex]; // eval int result; switch (step.Operation) { case Operation.Add: unchecked { result = lhs + rhs; } break; case Operation.Multiply: unchecked { result = lhs*rhs; } break; case Operation.Subtract: unchecked { result = lhs - rhs; } break; case Operation.Xor: result = lhs ^ rhs; break; case Operation.Or: result = lhs | rhs; break; case Operation.And: result = lhs & rhs; break; default: throw new InvalidOperationException(); } // write state[step.OutputIndex] = result; } } } // result is last state variable return state[state.Length - 1]; }
/// <summary> /// The function generated by specializing the hash function returned by Example. /// Obtained by: /// 1. Evaluating Specialize to get the expression representing the method. /// 2. Passing the method expression to WriteMethodToAssembly (below) to get an assembly. /// 3. Decompiling the assembly (with a tool like reflector). /// </summary> public static int SpecializedExampleFunction(IntStream stream1) { var num2 = 0; var num3 = 0x1a730b3b; var num4 = 0x13d66648; var num5 = 0x3e0c5f92; var buffer = new[] { 0x1000 }; while (true) { var num = stream1.Read(buffer); if (num == 0) { return(num5); } var num6 = 0; while (num6 < num) { var index = num6; num6 = index + 1; num2 = buffer[index]; num3 ^= num2; num4 -= num5; num5 ^= num3; num3 += num4; } } }
///<summary>The result of applying this hash function to the given data, by interpreting the operations in the inner loop.</summary> public int Interpret(IntStream data) { // copy initial state var state = InitialState.ToArray(); var buffer = new int[1 << 12]; while (true) { var n = data.Read(buffer); if (n == 0) { break; } // feed data through the state via custom steps for (var i = 0; i < n; i++) { // input into hash via first state variable state[0] = buffer[i]; // apply custom hashing steps foreach (var step in Steps) { // read var lhs = state[step.LeftInputIndex]; var rhs = state[step.RightInputIndex]; // eval int result; switch (step.Operation) { case Operation.Add: unchecked { result = lhs + rhs; } break; case Operation.Multiply: unchecked { result = lhs * rhs; } break; case Operation.Subtract: unchecked { result = lhs - rhs; } break; case Operation.Xor: result = lhs ^ rhs; break; case Operation.Or: result = lhs | rhs; break; case Operation.And: result = lhs & rhs; break; default: throw new InvalidOperationException(); } // write state[step.OutputIndex] = result; } } } // result is last state variable return(state[state.Length - 1]); }