Hash

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
10
Indexable
Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hash
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int min = 33;
            int max = 126;
            int diff = 3;
            Console.WriteLine("Escribe el texto a encriptar");
            string tohash = Console.ReadLine();
            char [] chars = tohash.ToCharArray();
            string hash_string = "";
            foreach (char c in chars)
            {
                int ascii = (int) c;
                int new_ascii = ascii + diff;
                if (new_ascii > 126)
                {
                    new_ascii = min + (diff - 1);
                }
                hash_string = hash_string+((char)new_ascii).ToString();
            }
            Console.WriteLine("Resultado");
            Console.WriteLine(hash_string);
            Console.WriteLine("\n");


            Console.WriteLine("Desencriptado");
            char[] chars2 = hash_string.ToCharArray();
            string unhash_string = "";
            foreach (char c in chars2)
            {
                int ascii = (int)c;
                int new_ascii = ascii - diff;
                if (new_ascii < 33)
                {
                    new_ascii = max - diff;
                }
                unhash_string = unhash_string + ((char)new_ascii).ToString();
            }
            Console.WriteLine(unhash_string);

            Console.ReadLine();
        }
    }
}