public static string NDESEncrypt(string encryptString, string encKey, string number) { int[] divisors = NDes.Getdivisor(number); //int[] divisors = new int[] { 1, 3 }; int m = int.Parse(number); int i, j; string cipherresult = string.Empty; string t = string.Empty; string subkey = string.Empty; for (i = 1; i <= m; i++) { if (i <= divisors.Length) { if (i % 2 == 0) { subkey = rightmovekey(encKey, divisors[i - 1]); t = encryptString; cipherresult = DES.DEScipher.Encrypt(t, subkey); encryptString = cipherresult; } else { subkey = leftmovekey(encKey, divisors[i - 1]); t = encryptString; cipherresult = DES.DEScipher.Encrypt(t, subkey); encryptString = cipherresult; } } else { j = i; do { j = j - divisors.Length; } while (j > divisors.Length); if (i % 2 == 0) { subkey = NDes.rightmovekey(encKey, divisors[j - 1]); t = encryptString; cipherresult = DES.DEScipher.Encrypt(t, subkey); encryptString = cipherresult; } else { subkey = NDes.leftmovekey(encKey, divisors[j - 1]); t = encryptString; cipherresult = DES.DEScipher.Encrypt(t, subkey); encryptString = cipherresult; } } } return(encryptString); }
public static string NDESDecrypt(string decryptString, string encKey, string number) { int[] divisors = NDes.Getdivisor(number); int m = int.Parse(number); int i, j; string decipherresult = string.Empty; string t = string.Empty; string subkey = string.Empty; for (i = m; i > 0; i--) { if (i <= divisors.Length) { if (i % 2 == 0) { subkey = rightmovekey(encKey, divisors[i - 1]); t = decryptString; decipherresult = DES.DEScipher.Decrypt(t, subkey); decryptString = decipherresult; } else { subkey = leftmovekey(encKey, divisors[i - 1]); t = decryptString; decipherresult = DES.DEScipher.Decrypt(t, subkey); decryptString = decipherresult; } } else { j = i; do { j = j - divisors.Length; } while (j > divisors.Length); if (i % 2 == 0) { subkey = NDes.rightmovekey(encKey, divisors[j - 1]); t = decryptString; decipherresult = DES.DEScipher.Decrypt(t, subkey); decryptString = decipherresult; } else { subkey = NDes.leftmovekey(encKey, divisors[j - 1]); t = decryptString; decipherresult = DES.DEScipher.Decrypt(t, subkey); decryptString = decipherresult; } } } return(decryptString); }