Encrypt String C#

Asked

Viewed 153 times

-1

I have the code below that decrypts an example X value (|xB779A:6AA6=@6::@7 and would look like http://seusite.com) however I do not know how to do the reverse, I wanted to make an application that encrypts this X value of the example.

type I have the value http://www.seusite.com.br and wanted to encrypt that amount

follows the code

private static string Descrypt(string source, short shift)
    {
        int num = Convert.ToInt32('\uffff');
        int num2 = Convert.ToInt32('\0');
        char[] array = source.ToCharArray();
        for (int i = 0; i < array.Length; i++)
        {
            int num3 = Convert.ToInt32(array[i]) + shift;
            if (num3 > num)
            {
                num3 -= num;
            }
            else if (num3 < num2)
            {
                num3 += num;
            }
            array[i] = Convert.ToChar(num3);
        }
        return new string(array);
    }


Webbrowser1.Url = new Uri(Descrypt("|xB779A:6AA6=@6::@7", -8) + "1.1.php", UriKind.Absolute);

1 answer

1


This "encryption" algorithm is quite simple. It simply adds the shift value to the character code. To "encrypt", subtract the value.

private static string Encrypt(string source, short shift)
{
    int num = Convert.ToInt32('\uffff');
    int num2 = Convert.ToInt32('\0');
    char[] array = source.ToCharArray();
    for (int i = 0; i < array.Length; i++)
    {
        int num3 = Convert.ToInt32(array[i]) - shift;
        if (num3 > num)
            num3 -= num;
        else if (num3 < num2)
            num3 += num;
        array[i] = Convert.ToChar(num3);
    }

    return new string(array);
}

Example:

Console.WriteLine(Decrypt("|xB779A:6AA6=@6::@7", -8));
Console.WriteLine(Encrypt("tp://192.99.58.228/", -8));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.