private void InputToOutput(Encoding encode) { otp = OneTimePadAlgorithm.Create(); otp.setInputLength(txtInput.Text.Length); if (rbEncrypt.Checked) { bool isNumeric = int.TryParse(txtSeed.Text, out _); if (isNumeric) { otp.setStringSeed(int.Parse(txtSeed.Text)); } else { otp.setStringSeed(txtSeed.Text); } otp.GenerateKey(); CryptoTransform ict = (CryptoTransform)otp.CreateEncryptor(otp.Key, null); byte[] inputText = encode.GetBytes(txtInput.Text); txtOTP.Text = encode.GetString(otp.Key); txtOutput.Text = encode.GetString(ict.TransformFinalBlock(inputText, 0, txtInput.Text.Length)); } else { otp.Key = encode.GetBytes(txtOTP.Text); CryptoTransform ict = (CryptoTransform)otp.CreateDecryptor(otp.Key, null); byte[] inputText = encode.GetBytes(txtInput.Text); txtOutput.Text = encode.GetString(ict.TransformFinalBlock(inputText, 0, txtInput.Text.Length)); } }
public override byte[] TransformFinal(byte[] input) { return(CryptoTransform.TransformFinalBlock(input, 0, input.Length)); }