4
private static void algoritmo(String input, String chave, Boolean b)
{
Console.WriteLine("Digite a mensagem: ");
input = Console.ReadLine();
Console.WriteLine("Digite a chave: ");
chave = Console.ReadLine();
input = input.ToUpper();
chave = chave.ToUpper();
if (b)
{
// para cada caracter da entrada, com exceção do espaço, converterá para valor ascii
for (int contaCar = 0; contaCar < input.Length; contaCar++)
{
if (input.Equals(" "))
{
output += input;
}
else
{
char carTex = (char)input[contaCar];
output += carTex;
}
}
Console.WriteLine(output);
// para cada caracter da chave, com exceção do espaço, converterá para valor ascii
for (int contaCar = 0; contaCar < chave.Length; contaCar++)
{
if (chave.Equals(" "))
{
codeKey += chave;
}
else
{
char asciiChave = (char)chave[contaCar];
codeKey += asciiChave;
}
}
Console.WriteLine(codeKey);
// agora que a mensagem está transformada em ascii(output) assim como a chave (codeKey),
// deverá ocorrer a codificação
for (int i = 0; i < output.Length; i++)
{
for (int j = 0; j < codeKey.Length; j++)
{
code = ((codeKey[j] + output[i]) - 65) % 26;
}
}
Console.Write(code);
Console.ReadKey();
}
The goal would be to make each key character receive its ASCII value and return as one array so I can do some sum operations between each ASCII value of each character. For example: ASCII word values "nome": [65, 67, ...]
and key ASCII values "cade": [65, 67, ...]
, so I would add the values of the same index of array.
How can I make for the output
and of codeKey
exit with ASCII input values?
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero