I'm having a problem with a program that I did for encryption and decryption from a hash, do not judge how it works, I did it while it was too much.
What is not working is decrypt, I believe it is by the replacerbyhash()
function, but I could not find the problem.
Code:
else if(type.ToLower() == "decrypt")
{
Console.WriteLine("Digite o hash.");
hash = Console.ReadLine();
Console.WriteLine("Digite a mensagem encriptada.");
txt = Console.ReadLine();
replacerbyhash();
replacer2();
}
Replacerbyhash method:
static void replacerbyhash()
{
for (int i = 0; i < 26; i++)
{
az[i] = hash.Remove(i * 4, 4);
}
}
Replacer2 Method:
static void replacer2()
{
txt = txt.Replace(az[0], "a");
txt = txt.Replace(az[1], "b");
txt = txt.Replace(az[2], "c");
txt = txt.Replace(az[3], "d");
txt = txt.Replace(az[4], "e");
txt = txt.Replace(az[5], "f");
txt = txt.Replace(az[6], "g");
txt = txt.Replace(az[7], "h");
txt = txt.Replace(az[8], "i");
txt = txt.Replace(az[9], "j");
txt = txt.Replace(az[10], "k");
txt = txt.Replace(az[11], "l");
txt = txt.Replace(az[12], "m");
txt = txt.Replace(az[13], "n");
txt = txt.Replace(az[14], "o");
txt = txt.Replace(az[15], "p");
txt = txt.Replace(az[16], "q");
txt = txt.Replace(az[17], "r");
txt = txt.Replace(az[18], "s");
txt = txt.Replace(az[19], "t");
txt = txt.Replace(az[20], "u");
txt = txt.Replace(az[21], "v");
txt = txt.Replace(az[22], "w");
txt = txt.Replace(az[23], "x");
txt = txt.Replace(az[24], "y");
txt = txt.Replace(az[25], "z");
}
How the Hash is done:
static void compile()
{
for (int i = 0; i < 26; i++)
{
az[i] = x.Next(1000, 9999).ToString();
}
}
I know the code is badly done, I did not think much to do it.