0
I’m having a problem with a program that I did for encryption and decryption from a hash, don’t judge how it works, I did it while it was very tied.
What is not working is the Decrypt, I believe it is the function replacerbyhash()
, but I couldn’t 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 Hash is made:
static void compile()
{
for (int i = 0; i < 26; i++)
{
az[i] = x.Next(1000, 9999).ToString();
}
}
I know the code is poorly done, I didn’t think much to do it.
can post an example of the hash and the example of an encrypted message ?
– Rovann Linhalis
It is difficult to say anything just with this excerpt, what I can say is that in fact not to do something much simpler, efficient and less tragic for GC. And if I understand correctly, you are using random to "encrypt", then I think I would just be soiling the data, IE, no one else can use it for anything.
– Maniero
@Yes, I know I’m doing it the wrong way, I only did it because I was too busy in class, this code is useless to me. But even so this problem I’m having has left me a little curious... Entire code.
– Francisco
@Rovannlinhalis The word "test". Hash:
25373944232485139036550471698470496693739437688485855615330811538489511846224254934738599164124870343271
Encrypted Message:4254903646224254
– Francisco