Problem with for and string.Remove

0

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.

    
asked by anonymous 31.05.2017 / 00:23

1 answer

1

Trying to understand what you're doing, the vector values would be those then (in bold), what's in italic has been removed by the Remove () function:

az [0] =      2537 39442324851390365504716984704966937394376884858556153308 11538489511846224254 93473859916412487034 3271

az [1] =      2537

... and so on ...

Maybe your intention was to use a SubString instead of remove, so that the values look like this:

az [0] = 2537 // a

az [1] = 3944 // b

c      d    e    f    g    h    i   j     k     l    m   n     o
2324 8513 9036 5504 7169 8470 4966 9373  9437 6884 8585 5615 3308‌ ​

 p     q    r   s    t    u    v     w    x    y    z
1153 8489 5118 4622 4254‌ ​9347 3859 9164 1248 7034‌ ​3271

So checking with

test = 4254 9036 4622 4254 

So just update your function:

static void replacerbyhash()
{
    for (int i = 0; i < 26; i++)
    {
        az[i] = hash.SubString(i * 4, 4);
    }
}
    
31.05.2017 / 01:04