I have to develop a code where it does the Cipher of Cesar encryption, the characters that I should use should be in this sequence; A ~ Z, (whitespace), 0 ~ 9. I already developed a lot of the code, but I came across a problem;
for (int i = 0; i < palavra.Length; i++){
//Pego Valor Dec. da palavra
ASCIIP = (int)palavra[i], x = 1, y = 0;
while (x != 0){
//Verifico qual índice esta o valor dec.
if (ASCIIP == tabelaASCII[y]){
//Somo a chave da cifra
ASCIIC = tabelaASCII[y + 4];
//Converto para Char o valor Criptografado
encrypt += Char.ConvertFromUtf32(ASCIIC);
x = 0;
}
y++;
}
return encrypt;
}
My problem is in the following line ASCIIC = tabelaASCII[y + 4];
How do I go back to the beginning of the array when the sum of the index pops up?
Example:
int [] array = {1,2,3,4,5}, y = 1, resultado;
resultado = array[y];
/* resultado = 2 */
resultado = array[y+4];
/* resultado = 1 */