Добавил:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
31.01.2021
Размер:
46.52 Кб
Скачать

Internal static ulong Bytes_To_uInt64(byte[] bs, ulong off)

{

ulong n = (ulong)bs[off] << 56;

n |= (ulong)bs[++off] << 48;

n |= (ulong)bs[++off] << 40;

n |= (ulong)bs[++off] << 32;

n |= (ulong)bs[++off] << 24;

n |= (ulong)bs[++off] << 16;

n |= (ulong)bs[++off] << 8;

n |= (ulong)bs[++off];

return n;

}

private static ulong rotr(ulong x, int n)

{

return ((x >> n) | (x << 64 - n));

}

private static ulong Delta0(ulong x)

{

return rotr(x, 1) ^ rotr(x, 8) ^ (x >> 7);

}

private static ulong Delta1(ulong x)

{

return rotr(x, 19) ^ rotr(x, 61) ^ (x >> 6);

}

private static ulong Ch(ulong x, ulong y, ulong z)

{

return (x & y) ^ ((~x) & z);

}

private static ulong Maj(ulong x, ulong y, ulong z)

{

return (x & y) ^ (x & z) ^ (y & z);

}

private static ulong Sigma0(ulong x)

{

return rotr(x, 28) ^ rotr(x, 34) ^ rotr(x, 39);

}

private static ulong Sigma1(ulong x)

{

return rotr(x, 14) ^ rotr(x, 18) ^ rotr(x, 41);

}

private void processBlock()

{

ulong a = digest.H0;

ulong b = digest.H1;

ulong c = digest.H2;

ulong d = digest.H3;

ulong e = digest.H4;

ulong f = digest.H5;

ulong g = digest.H6;

ulong h = digest.H7;

ulong T1 = 0, T2 = 0;

for (int i = 0; i < 80; i++)

{

T1 = h + Sigma1(e) + Ch(e, f, g) + W[i] + K[i];

T2 = Sigma0(a) + Maj(a, b, c);

h = g;

g = f;

f = e;

e = d + T1;

d = c;

c = b;

b = a;

a = T1 + T2;

}

digest.H0 += a;

digest.H1 += b;

digest.H2 += c;

digest.H3 += d;

digest.H4 += e;

digest.H5 += f;

digest.H6 += g;

digest.H7 += h;

}

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Security.Cryptography;

namespace SHA_512

{

class Program

{

static void Main(string[] args)

{

string text = Console.ReadLine();

SHA512.Sha512Digest sha = new SHA512.Sha512Digest();

SHA_512.SHA512.Digest x = sha.hash(Encoding.UTF8.GetBytes(text));

byte[] hashh = new SHA512Managed().ComputeHash(Encoding.UTF8.GetBytes(text));

string hashString = string.Empty;

int Length = hashh.Length;

for (int j = 0; j < Length; j++)

hashString += String.Format("{0:x2}", hashh[j]);

string hash = x.H0.ToString("X") + x.H1.ToString("X") + x.H2.ToString("X") + x.H3.ToString("X") + x.H4.ToString("X") + x.H5.ToString("X") + x.H6.ToString("X") + x.H7.ToString("X");

Console.WriteLine("Хеш программы:");

Console.WriteLine(hash.ToLower());

Console.WriteLine("Хеш втроенного класса (для проверки):");

Console.WriteLine(hashString);

Console.ReadKey();

}

}

}