1
I have to develop a code where he does the Cesar Cipher encryption, the characters I should use should be in this sequence; A~Z,(blank space),0~9. I’ve developed most of the code, only I ran into 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 on the following line ASCIIC = tabelaASCII[y + 4];
How do I go back to the beginning of the array when the sum of the index overflows?
Example:
int [] array = {1,2,3,4,5}, y = 1, resultado;
resultado = array[y];
/* resultado = 2 */
resultado = array[y+4];
/* resultado = 1 */
The answer below helped you, please vote or from your comment on helping, to improve the question.
– Edvaldo Farias