Internal static uint Bytes_To_uInt32(byte[] bs, ulong off)
{
uint n = (uint)bs[off] << 24;
n |= (uint)bs[++off] << 16;
n |= (uint)bs[++off] << 8;
n |= (uint)bs[++off];
return n;
}
private static uint rotr(uint x, int n)
{
return ((x >> n) | (x << 32 - n));
}
private static uint Delta0(uint x)
{
return rotr(x, 7) ^ rotr(x, 18) ^ (x >> 3);
}
private static uint Delta1(uint x)
{
return rotr(x, 17) ^ rotr(x, 19) ^ (x >> 10);
}
private static uint Ch(uint x, uint y, uint z)
{
return (x & y) ^ ((~x) & z);
}
private static uint Maj(uint x, uint y, uint z)
{
return (x & y) ^ (x & z) ^ (y & z);
}
private static uint Sigma0(uint x)
{
return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
}
private static uint Sigma1(uint x)
{
return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
}
private void processBlock()
{
uint a = digest.H0;
uint b = digest.H1;
uint c = digest.H2;
uint d = digest.H3;
uint e = digest.H4;
uint f = digest.H5;
uint g = digest.H6;
uint h = digest.H7;
uint T1 = 0, T2 = 0;
for (int i = 0; i < 64; i++)
{
T1 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[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_256
{
class Program
{
static void Main(string[] args)
{
string text = Console.ReadLine();
SHA256.Sha256Digest sha = new SHA256.Sha256Digest();
SHA_256.SHA256.Digest x = sha.hash(Encoding.UTF8.GetBytes(text));
byte[] hashh = new SHA256Managed().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();
}
}
}