void Cifrar() { TxtCifrado.Clear(); int y, z; string exadecimal; int lettertransposition; string textoaux = TxtNormal.Text.ToUpper(); string texto = ""; //le quito los espacios y saltos a el texto for (int i = 0; i < TxtNormal.Text.Length; i++) { if (textoaux[i] != ' ' && textoaux[i] != '\n') { texto += textoaux[i]; } } for (int i = 0; i < texto.Length; i++) { ///con la i del for valido si la posicion de una letra del texto esta en numero par o impar ///en otras palabras si me sale la i par ///aplico una fucnion matematica y si es impar aplico otra if (Valida_Par_Impar(i)) { char aux = texto[i]; int x = aux; y = (x + 20); z = (x * 2); x += (y + z); x = (x / 2); lettertransposition = TranspositionEncrypt(x); exadecimal = ConverToExadecimal(lettertransposition); TxtCifrado.Text += exadecimal + " "; } else { char aux = texto[i]; int x = aux; y = (x + 20); z = (x * 2); x += (y + z); x = (x / 4); lettertransposition = TranspositionEncrypt(x); exadecimal = ConverToExadecimal(lettertransposition); TxtCifrado.Text += exadecimal + " "; } } }
void Descifrar() { TxtCifrado.Clear(); string letter = TxtNormal.Text; string exadecimal = ""; int numdecimal = 0, convertToPlainText = 0, count = 0; for (int i = 0; i < letter.Length; i++) { if (letter[i] != ' ') { exadecimal += letter[i]; } if (exadecimal.Length == 2) { numdecimal = ConvertToDecimal(exadecimal); exadecimal = ""; convertToPlainText = TranspositionDecrypt(numdecimal); TxtCifrado.Text += ConvertToPlainText(convertToPlainText, count); count++; } } }