Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Security.Cryptography;
  4.  
  5. public class Program
  6. {
  7. public static byte[] StringToByteArray(String hex)
  8. {
  9. int NumberChars = hex.Length;
  10. byte[] bytes = new byte[NumberChars / 2];
  11. for (int i = 0; i < NumberChars; i += 2)
  12. bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
  13. return bytes;
  14. }
  15. public static string ByteArrayToString(byte[] ba)
  16. {
  17. StringBuilder hex = new StringBuilder(ba.Length * 2);
  18. foreach (byte b in ba)
  19. hex.AppendFormat("{0:x2}", b);
  20. return hex.ToString();
  21. }
  22.  
  23. public static void Main()
  24. {
  25. string input="d8818b38a14e7461e87301ad4b9809b558bcbca816b650cd470452e018ada255";
  26. string output="740f81cd7deed90102a36e41a74cbe7373856ff647c66d0c945db8c4dfc67130";
  27.  
  28. Console.WriteLine("Expected:");
  29. Console.WriteLine(output);
  30.  
  31. var serverSeed = StringToByteArray(input);
  32. using (var sha = SHA256.Create())
  33. {
  34. var hash = sha.ComputeHash(serverSeed);
  35. string ou=BitConverter.ToString(SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(input))).Replace("-", "").ToLower();
  36. Console.WriteLine("\nActual:");
  37. Console.WriteLine(ou);
  38.  
  39. if(output==ou){
  40. Console.WriteLine("\nThey are the same");
  41. }else Console.WriteLine("\nThey aren't the same");
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement