private string Plaintext(string encryptedString, string key) { string send = string.Empty; string plaintext = string.Empty; for (int i = 0; i < encryptedString.Length; i += 16) { if (encryptedString.Length - i > 16) { send = encryptedString.Substring(i, 16); } else { send = encryptedString.Substring(i, encryptedString.Length - i); } if (send.Length != 16) { int missing = 16 - send.Length; for (int j = 0; j < missing; j++) { send += "0"; } } var des = new DESClass() { Ciphertext = send, Key = key }; des.DecipherString(rounds); plaintext += des.Plaintext; } return(plaintext); }
private string Ciphertext(string sourceString, string key) { string send = string.Empty; string ciphertext = string.Empty; for (int i = 0; i < sourceString.Length; i += 8) { if (sourceString.Length - i > 8) { send = sourceString.Substring(i, 8); } else { send = sourceString.Substring(i, sourceString.Length - i); } if (send.Length != 8) { int missing = 8 - send.Length; for (int j = 0; j < missing; j++) { send += "0"; } } var des = new DESClass() { Plaintext = send, Key = key }; des.CipherString(rounds); ciphertext += des.Ciphertext; } return(ciphertext); }
public void AllAroundHexTest() { string M = ""; string key = ""; char[] possible = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; Random random = new Random(); int posicion; for (var j = 0; j < 16; j++) { posicion = random.Next(16); M += possible[posicion]; posicion = random.Next(16); key += possible[posicion]; } var cipher = new DESClass(); cipher.Plaintext = M; cipher.Key = key; cipher.CipherHex(16); var decipher = new DESClass(); decipher.Ciphertext = cipher.Ciphertext; decipher.Key = key; decipher.DecipherHex(16); Assert.AreEqual(M, decipher.Plaintext, true); }
public string Decrypt(string encryptedString) { var des = new DESClass() { Ciphertext = encryptedString, Key = key }; des.DecipherString(rounds); return(des.Plaintext); }
public string Encrypt(string sourceString) { var des = new DESClass() { Plaintext = sourceString, Key = key }; des.CipherString(rounds); return(des.Ciphertext); }
public void DecipherHexTest() { string M = "85E813540F0AB405"; string key = "133457799BBCDFF1"; var test = new DESClass(); test.Ciphertext = M; test.Key = key; test.DecipherHex(16); Assert.AreEqual("0123456789ABCDEF", test.Plaintext, true); }
private void cipherButton_Click(object sender, RoutedEventArgs e) { string plaintext = messagebox.Text; string key = keybox.Text; string ciphertext = string.Empty; string works = string.Empty; string send = string.Empty; bool hex = (bool)hexRadio.IsChecked; int round = roundBox.SelectedIndex + 1; if (hex) { for (int i = 0; i < plaintext.Length; i += 16) { if (plaintext.Length - i > 16) { send = plaintext.Substring(i, 16); } else { send = plaintext.Substring(i, plaintext.Length - i); } if (send.Length != 16) { int missing = 16 - send.Length; for (int j = 0; j < missing; j++) { send += "0"; } } works += string.Format("Part {0}{1}", i, Environment.NewLine); var des = new DESClass() { Plaintext = send, Key = key }; des.CipherHex(round); works += string.Format("{0}{1}{1}", des.Work, Environment.NewLine); ciphertext += des.Ciphertext; } } else { for (int i = 0; i < plaintext.Length; i += 8) { if (plaintext.Length - i > 8) { send = plaintext.Substring(i, 8); } else { send = plaintext.Substring(i, plaintext.Length - i); } if (send.Length != 8) { int missing = 8 - send.Length; for (int j = 0; j < missing; j++) { send += "0"; } } works += string.Format("Part {0}{1}", i, Environment.NewLine); var des = new DESClass() { Plaintext = send, Key = key }; des.CipherString(round); works += string.Format("{0}{1}{1}", des.Work, Environment.NewLine); ciphertext += des.Ciphertext; } } workText.Text = string.Format("{0}{1} CipherBytes: {2}", works, Environment.NewLine, ciphertext); }