public string DoCycles(string L0, string R0, Keys keys, bool IsReverse) { string Ln = "", Rn = "", Ln_1 = L0, Rn_1 = R0; int i = 0; if (IsReverse == true) { i = 15; } while (IsEnough(i, IsReverse)) { Ln = Rn_1; Rn = XOR(Ln_1, F(Rn_1, keys.Kn[i])); Ln_1 = Ln; Rn_1 = Rn; if (IsReverse == false) { i += 1; } else { i -= 1; } } string R16L16 = Rn + Ln; string EncryptedBinaryText = DoPermutation(R16L16, DESData.FinalPermutation); return EncryptedBinaryText; }
public Keys SetAllKeys(string C0, string D0) { Keys keys = new Keys(); keys.Cn[0] = C0; keys.Dn[0] = D0; for (int i = 1; i < keys.Cn.Length; i++) { keys.Cn[i] = LeftShift(keys.Cn[i - 1], DESData.Shifts[i]); keys.Dn[i] = LeftShift(keys.Dn[i - 1], DESData.Shifts[i]); keys.Kn[i - 1] = DoPermutation(keys.Cn[i] + keys.Dn[i], DESData.PermutationKeyCompression); } return keys; }