public void CryptoDES_RandomIV_Test() { //Arrange byte[] key = { 158, 23, 64, 96, 57, 225, 36, 85 }; CryptoSymmetric crypto = new CryptoDES(key); string originalMessage = "I love cryptography and DES with a 64-bits key"; string encryptedMessage = crypto.Encrypt(originalMessage); //Act string decryptedMessage = crypto.Decrypt(encryptedMessage); //Assert Assert.AreNotEqual(originalMessage, encryptedMessage); Assert.AreEqual(originalMessage, decryptedMessage); }
public void CryptoDES_FixedIV_Test() { //Arrange byte[] key = { 158, 23, 64, 96, 57, 225, 36, 85 }; byte[] iv = { 63, 208, 159, 46, 37, 77, 1, 59 }; CryptoSymmetric crypto = new CryptoDES(key); crypto.SetIV(iv); string originalMessage = "I love cryptography and DES with a 64-bits key"; string encryptedMessage = crypto.Encrypt(originalMessage); //Act string decryptedMessage = crypto.Decrypt(encryptedMessage); //Assert Assert.AreNotEqual(originalMessage, encryptedMessage); Assert.AreEqual(originalMessage, decryptedMessage); }
public static void loadData() { string line = ""; StreamReader studentFile = new StreamReader("student.txt"); CryptoSymmetric crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = studentFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); StudentTable.Add(new Student() { Id = int.Parse(items[0]), FirstName = items[1], LastName = items[2], Password = items[3], EntranceYear = items[4].ToString() }); } studentFile.Close(); StreamReader teacherFile = new StreamReader("teacher.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = teacherFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); TeacherTable.Add(new Teacher() { Id = int.Parse(items[0]), FirstName = items[1], LastName = items[3], Password = items[3] }); } teacherFile.Close(); StreamReader courseFile = new StreamReader("course.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = courseFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); CourseTable.Add(new Course() { Id = int.Parse(items[0]), ECT = int.Parse(items[1]), Name = items[2], type = items[3] }); } courseFile.Close(); StreamReader termFile = new StreamReader("term.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = termFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); TermTable.Add(new Term() { TermNum = int.Parse(items[0]) , TermName = items[1] }); } termFile.Close(); StreamReader prereQuisiteFile = new StreamReader("prerequisite.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = prereQuisiteFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); preQuisiteTable.Add(new PreQuisite() { Course1 = (CourseTable.Select(x => x).Where(x => x.Id == int.Parse(items[0])).ToArray())[0] , Course2 = (CourseTable.Select(x => x).Where(x => x.Id == int.Parse(items[1])).ToArray())[0] , Status = items[2] }); } prereQuisiteFile.Close(); StreamReader termCourseFile = new StreamReader("termcourse.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = termCourseFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); termCourseTable.Add(new TermCourse() { Id = int.Parse(items[0]), Course = (CourseTable.Select(x => x).Where(x => x.Id == int.Parse(items[1])).ToArray())[0], Term = (TermTable.Select(x => x).Where(x => x.TermNum == int.Parse(items[2])).ToArray())[0], Teacher = (TeacherTable.Select(x => x).Where(x => x.Id == int.Parse(items[3])).ToArray())[0], Time = int.Parse(items[4]), Place = items[5], Capacity = int.Parse(items[6]) }); ; } termCourseFile.Close(); StreamReader termCourseStudentFile = new StreamReader("termcoursestudent.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = termCourseStudentFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); termCourseStudentTable.Add(new TermCourseStudent() { Mark = double.Parse(items[0]) , ObjectionToMark = items[1] , AnswerToObjection = items[2] , TermCourse = (termCourseTable.Select(x => x).Where(x => x.Id == int.Parse(items[3])).ToArray())[0] , Student = (StudentTable.Select(x => x).Where(x => x.Id == int.Parse(items[4])).ToArray())[0] , Status = items[5] }); } termCourseStudentFile.Close(); StreamReader clerkFile = new StreamReader("clerk.txt"); crypto = new CryptoDES(new byte[] { 158, 23, 64, 96, 57, 225, 36, 85 }); while ((line = clerkFile.ReadLine()) != null) { line = crypto.Decrypt(line); var items = line.Split('\t'); ClerkTable.Add(new Clerk() { Id = int.Parse(items[0]) , FirstName = items[1] , LastName = items[2] , Password = items[3] }); } clerkFile.Close(); }