public string OutputResults() { const int varIDlength = 2; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 32; i++) { sb.Append(i.ToString().PadLeft(2)); sb.Append(": "); for (int j = 0; j < xorOperations[i].Count; j++) { var t = xorOperations[i].ElementAt(j).Key; sb.AppendID(t.FirstVarID, varIDlength); sb.Append('.'); sb.AppendID(t.SecondVarID, varIDlength); sb.Append(" | "); } sb.Length = sb.Length - 2; sb.AppendLine(); } return sb.ToString(); }
private void AppendStructure(StringBuilder sb, SortedDictionary<ANDCombination, object>[] xorEq) { const int varIDlength = 2; for (int i = 0; i < xorEq.Length; i++) { sb.Append(i.ToString().PadLeft(2)); sb.Append(": "); for (int j = 0; j < xorEq[i].Count; j++) { var t = xorEq[i].ElementAt(j).Key; sb.AppendID(t.FirstVarID, varIDlength); sb.Append('.'); sb.AppendID(t.SecondVarID, varIDlength); sb.Append(" | "); } sb.Length = sb.Length - 2; sb.AppendLine(); } }
private void btnBuildCode_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("const int "); { int i = 0; while (i < numBits.Value) { sb.Append(" "); for (int j = 0; j < 10 && i < numBits.Value; j++) { sb.Append("v"); sb.AppendID(i, 2); sb.Append(" = "); sb.AppendID(i, 2); sb.Append(", "); i++; } sb.Length -= 1; sb.AppendLine(); } } sb.Length -= 3; sb.AppendLine(";"); sb.AppendLine(); int DataSize = (int)numBits.Value / 2; for (int i = 0; i < DataSize; i++) { int termCount = i + 1; sb.Append("new ulong[] {(1uL << v"); for (int j = 0; j < termCount; j++) { //sb.Append((char)(97 + 2 * (ii - jj))); sb.AppendID(j, 2); sb.Append(")|(1uL << v"); //sb.Append((char)(97 + 2 * jj + 1)); sb.AppendID(DataSize + i - j, 2); sb.Append("), (1uL << v"); } sb.Length -= 10; sb.AppendLine("},"); } for (int i = DataSize; i < DataSize * 2; i++) { int termCount = DataSize * 2 - i - 1; sb.Append("new ulong[] {(1uL << v"); for (int j = 0; j < termCount; j++) { //sb.Append((char)(97 + 2 * (ii - jj))); sb.AppendID(i - DataSize + j + 1, 2); sb.Append(")|(1uL << v"); //sb.Append((char)(97 + 2 * jj + 1)); sb.AppendID(DataSize * 2 - 1 - j, 2); sb.Append("), (1uL << v"); } sb.Length -= 10; sb.AppendLine("},"); } sb.Length -= 1; tbOut.Text = sb.ToString(); }
//private class v //{ // public const int // a = 0, b = 1, c = 2, d = 3, e = 4, f = 5, g = 6, h = 7, i = 8, j = 9, k = 10; //} private void button6_Click(object sender, EventArgs eArgs) { //const int // a = 0, b = 1, c = 2, d = 3, e = 4, f = 5, g = 6, h = 7, i = 8, j = 9, k = 10, l = 11, m = 12, // n = 13, o = 14, p = 15, q = 16, r = 17, s = 18, t = 19, u = 20, v = 21, w = 22, x = 23, y = 24, z = 25, // A = 26, B = 27, C = 28, D = 29, E = 30, F = 31, G = 32, H = 33, I = 34, J = 35, K = 36, L = 37, M = 38; //uint[][] ands = new uint[][] //{ // new uint[] {(1u << a)|(1u << b)}, // new uint[] {(1u << c)|(1u << b), (1u << a)|(1u << d)}, // new uint[] {(1u << e)|(1u << b), (1u << c)|(1u << d), (1u << a)|(1u << f)}, // new uint[] {(1u << g)|(1u << b), (1u << e)|(1u << d), (1u << c)|(1u << f), (1u << a)|(1u << h)}, // new uint[] {(1u << i)|(1u << b), (1u << g)|(1u << d), (1u << e)|(1u << f), (1u << c)|(1u << h), (1u << a)|(1u << j)}, // new uint[] {(1u << k)|(1u << b), (1u << i)|(1u << d), (1u << g)|(1u << f), (1u << e)|(1u << h), (1u << c)|(1u << j), (1u << a)|(1u << l)}, // new uint[] {(1u << m)|(1u << b), (1u << k)|(1u << d), (1u << i)|(1u << f), (1u << g)|(1u << h), (1u << e)|(1u << j), (1u << c)|(1u << l), (1u << a)|(1u << n)}, // new uint[] {(1u << o)|(1u << b), (1u << m)|(1u << d), (1u << k)|(1u << f), (1u << i)|(1u << h), (1u << g)|(1u << j), (1u << e)|(1u << l), (1u << c)|(1u << n), (1u << a)|(1u << p)}, // new uint[] {(1u << q)|(1u << b), (1u << o)|(1u << d), (1u << m)|(1u << f), (1u << k)|(1u << h), (1u << i)|(1u << j), (1u << g)|(1u << l), (1u << e)|(1u << n), (1u << c)|(1u << p), (1u << a)|(1u << r)}, // new uint[] {(1u << s)|(1u << b), (1u << q)|(1u << d), (1u << o)|(1u << f), (1u << m)|(1u << h), (1u << k)|(1u << j), (1u << i)|(1u << l), (1u << g)|(1u << n), (1u << e)|(1u << p), (1u << c)|(1u << r), (1u << a)|(1u << t)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v), (1u << a)|(1u << v)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v)}, // new uint[] {(1u << u)|(1u << b), (1u << s)|(1u << d), (1u << q)|(1u << f), (1u << o)|(1u << h), (1u << m)|(1u << j), (1u << k)|(1u << l), (1u << i)|(1u << n), (1u << g)|(1u << p), (1u << e)|(1u << r), (1u << c)|(1u << r), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v), (1u << a)|(1u << v)} //}; // hand done //const int // v00 = 00, v01 = 01, v02 = 02, v03 = 03, v04 = 04, v05 = 05, v06 = 06, v07 = 07, v08 = 08, v09 = 09, // v10 = 10, v11 = 11, v12 = 12, v13 = 13, v14 = 14, v15 = 15, v16 = 16, v17 = 17, v18 = 18, v19 = 19, // v20 = 20, v21 = 21, v22 = 22, v23 = 23, v24 = 24, v25 = 25, v26 = 26, v27 = 27, v28 = 28, v29 = 29, // v30 = 30, v31 = 31, v32 = 32, v33 = 33, v34 = 34, v35 = 35, v36 = 36, v37 = 37, v38 = 38, v39 = 39, // v40 = 40, v41 = 41, v42 = 42, v43 = 43, v44 = 44, v45 = 45, v46 = 46, v47 = 47, v48 = 48, v49 = 49, // v50 = 50, v51 = 51, v52 = 52, v53 = 53, v54 = 54, v55 = 55, v56 = 56, v57 = 57, v58 = 58, v59 = 59, // v60 = 60, v61 = 61, v62 = 62, v63 = 63, v64 = 64, v65 = 65, v66 = 66, v67 = 67, v68 = 68, v69 = 69, // v70 = 70, v71 = 71, v72 = 72, v73 = 73, v74 = 74, v75 = 75, v76 = 76, v77 = 77, v78 = 78, v79 = 79, // v80 = 80, v81 = 81, v82 = 82, v83 = 83, v84 = 84, v85 = 85, v86 = 86, v87 = 87, v88 = 88, v89 = 89, // v90 = 90, v91 = 91, v92 = 92, v93 = 93, v94 = 94, v95 = 95, v96 = 96, v97 = 97, v98 = 98, v99 = 99; uint[][] ands = new uint[][] { //new uint[] {(1u << v00)|(1u << v01)}, //new uint[] {(1u << v02)|(1u << v01), (1u << v00)|(1u << v03)}, //new uint[] {(1u << v04)|(1u << v01), (1u << v02)|(1u << v03), (1u << v00)|(1u << v05)}, //new uint[] {(1u << v06)|(1u << v01), (1u << v04)|(1u << v03), (1u << v02)|(1u << v05), (1u << v00)|(1u << v07)}, //new uint[] {(1u << v08)|(1u << v01), (1u << v06)|(1u << v03), (1u << v04)|(1u << v05), (1u << v02)|(1u << v07), (1u << v00)|(1u << v09)}, //new uint[] {(1u << v10)|(1u << v01), (1u << v08)|(1u << v03), (1u << v06)|(1u << v05), (1u << v04)|(1u << v07), (1u << v02)|(1u << v09), (1u << v00)|(1u << v11)}, //new uint[] {(1u << v12)|(1u << v01), (1u << v10)|(1u << v03), (1u << v08)|(1u << v05), (1u << v06)|(1u << v07), (1u << v04)|(1u << v09), (1u << v02)|(1u << v11), (1u << v00)|(1u << v13)}, //new uint[] {(1u << v14)|(1u << v01), (1u << v12)|(1u << v03), (1u << v10)|(1u << v05), (1u << v08)|(1u << v07), (1u << v06)|(1u << v09), (1u << v04)|(1u << v11), (1u << v02)|(1u << v13), (1u << v00)|(1u << v15)}, //new uint[] {(1u << v16)|(1u << v01), (1u << v14)|(1u << v03), (1u << v12)|(1u << v05), (1u << v10)|(1u << v07), (1u << v08)|(1u << v09), (1u << v06)|(1u << v11), (1u << v04)|(1u << v13), (1u << v02)|(1u << v15), (1u << v00)|(1u << v17)}, //new uint[] {(1u << v18)|(1u << v01), (1u << v16)|(1u << v03), (1u << v14)|(1u << v05), (1u << v12)|(1u << v07), (1u << v10)|(1u << v09), (1u << v08)|(1u << v11), (1u << v06)|(1u << v13), (1u << v04)|(1u << v15), (1u << v02)|(1u << v17), (1u << v00)|(1u << v19)}, //new uint[] {(1u << v20)|(1u << v01), (1u << v18)|(1u << v03), (1u << v16)|(1u << v05), (1u << v14)|(1u << v07), (1u << v12)|(1u << v09), (1u << v10)|(1u << v11), (1u << v08)|(1u << v13), (1u << v06)|(1u << v15), (1u << v04)|(1u << v17), (1u << v02)|(1u << v19), (1u << v00)|(1u << v21)}, //new uint[] {(1u << v22)|(1u << v01), (1u << v20)|(1u << v03), (1u << v18)|(1u << v05), (1u << v16)|(1u << v07), (1u << v14)|(1u << v09), (1u << v12)|(1u << v11), (1u << v10)|(1u << v13), (1u << v08)|(1u << v15), (1u << v06)|(1u << v17), (1u << v04)|(1u << v19), (1u << v02)|(1u << v21), (1u << v00)|(1u << v23)}, //new uint[] {(1u << v24)|(1u << v01), (1u << v22)|(1u << v03), (1u << v20)|(1u << v05), (1u << v18)|(1u << v07), (1u << v16)|(1u << v09), (1u << v14)|(1u << v11), (1u << v12)|(1u << v13), (1u << v10)|(1u << v15), (1u << v08)|(1u << v17), (1u << v06)|(1u << v19), (1u << v04)|(1u << v21), (1u << v02)|(1u << v23), (1u << v00)|(1u << v25)}, //new uint[] {(1u << v26)|(1u << v01), (1u << v24)|(1u << v03), (1u << v22)|(1u << v05), (1u << v20)|(1u << v07), (1u << v18)|(1u << v09), (1u << v16)|(1u << v11), (1u << v14)|(1u << v13), (1u << v12)|(1u << v15), (1u << v10)|(1u << v17), (1u << v08)|(1u << v19), (1u << v06)|(1u << v21), (1u << v04)|(1u << v23), (1u << v02)|(1u << v25), (1u << v00)|(1u << v27)}, //new uint[] {(1u << v28)|(1u << v01), (1u << v26)|(1u << v03), (1u << v24)|(1u << v05), (1u << v22)|(1u << v07), (1u << v20)|(1u << v09), (1u << v18)|(1u << v11), (1u << v16)|(1u << v13), (1u << v14)|(1u << v15), (1u << v12)|(1u << v17), (1u << v10)|(1u << v19), (1u << v08)|(1u << v21), (1u << v06)|(1u << v23), (1u << v04)|(1u << v25), (1u << v02)|(1u << v27), (1u << v00)|(1u << v29)}, //new uint[] {(1u << v30)|(1u << v01), (1u << v28)|(1u << v03), (1u << v26)|(1u << v05), (1u << v24)|(1u << v07), (1u << v22)|(1u << v09), (1u << v20)|(1u << v11), (1u << v18)|(1u << v13), (1u << v16)|(1u << v15), (1u << v14)|(1u << v17), (1u << v12)|(1u << v19), (1u << v10)|(1u << v21), (1u << v08)|(1u << v23), (1u << v06)|(1u << v25), (1u << v04)|(1u << v27), (1u << v02)|(1u << v29), (1u << v00)|(1u << v31)} }; StringBuilder sb = new StringBuilder(); sb.AppendLine("const int "); for (int ii = 0; ii < 10; ii++) { sb.Append(" "); for (int jj = 0; jj < 10; jj++) { sb.Append("v"); sb.AppendID(ii * 10 + jj, 2); sb.Append(" = "); sb.AppendID(ii * 10 + jj, 2); sb.Append(", "); } sb.Length -= 1; sb.AppendLine(); } sb.Length -= 3; sb.AppendLine(";"); sb.AppendLine(); for (int ii = 0; ii < 16; ii++) { int termCount = ii + 1; sb.Append("new uint[] {(1u << v"); for (int jj = 0; jj < termCount; jj++) { //sb.Append((char)(97 + 2 * (ii - jj))); sb.AppendID(2 * (ii - jj), 2); sb.Append(")|(1u << v"); //sb.Append((char)(97 + 2 * jj + 1)); sb.AppendID(2 * jj + 1, 2); sb.Append("), (1u << v"); } sb.Length -= 10; sb.AppendLine("},"); } //tbOut.Text = sb.ToString(); sb.Clear(); const int MaxRow = 13; //11 const int NumOfVar = 2 * MaxRow; int TTRows = (int)Math.Pow(2, NumOfVar); bool[,] testResults = new bool[TTRows, MaxRow]; for (uint itt = 0; itt < TTRows; itt++) { for (int itt2 = 0; itt2 < MaxRow; itt2++) { for (int itt3 = 0; itt3 < itt2 + 1; itt3++) { if ((ands[itt2][itt3] & itt) == ands[itt2][itt3]) { testResults[itt, itt2] = !testResults[itt, itt2]; } } int prev = itt2 - 1; if (prev >= 0 && testResults[itt, prev]) { testResults[itt, itt2] = !testResults[itt, itt2]; } } } int[] countFalses = new int[MaxRow]; for (int itt1 = 0; itt1 < TTRows; itt1++) { for (int itt2 = 0; itt2 < MaxRow; itt2++) { if (!testResults[itt1, itt2]) { countFalses[itt2]++; } } } sb.Append("The number of combinations of "); sb.Append(MaxRow); sb.AppendLine(" bits that will be valid for consecutive false bits in the encription."); sb.AppendLine("The tests are clumlitave and employ the results of the prior equation tests: "); sb.AppendLine(); for (int i = 0; i < MaxRow; i++) { sb.Append("Eq/Bit Index "); sb.Append(i); sb.Append(": "); sb.Append(countFalses[i]); sb.AppendLine(); } tbOut.Text = sb.ToString(); }