fork(1) download
  1. using System;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8.  
  9. namespace nboard
  10. {
  11. class Program
  12. {
  13. static void Main()
  14. {
  15. Console.WriteLine(HashCalculator.Calculate("test"));
  16. }
  17. }
  18.  
  19. static class NanoEncoding
  20. {
  21. static string charset =
  22. "?!\"#$%&'()*+,-./0123456789:;<=> @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"+
  23. "ЎўЄєІіЇїАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяčšžćśźńŭłČŠŽĆŚŽŽŬŁ" +
  24. "№©«»±®Ґґ°™—“”’‘…–\n\r\t";
  25.  
  26. public static byte[] GetBytes(string str)
  27. {
  28. byte[] bytes = new byte[str.Length];
  29. int i = 0;
  30.  
  31. foreach (var c in str)
  32. {
  33. int iof = charset.IndexOf(c);
  34. if (iof == -1) bytes[i++] = 0;
  35. else bytes[i++] = (byte)iof;
  36. }
  37.  
  38. return bytes;
  39. }
  40.  
  41. public static string GetString(byte[] bytes)
  42. {
  43. char[] chars = new char[bytes.Length];
  44. int i = 0;
  45.  
  46. foreach (var b in bytes)
  47. {
  48. if (b > charset.Length) chars[i++] = '?';
  49. else chars[i++] = charset[b];
  50. }
  51.  
  52. return new string(chars);
  53. }
  54. }
  55.  
  56. static class HashCalculator
  57. {
  58. public const int HashCrop = 16;
  59.  
  60. public static string Calculate(string raw)
  61. {
  62. byte[] bhash = SHA256.Create().ComputeHash(NanoEncoding.GetBytes(raw));
  63. StringBuilder sb = new StringBuilder();
  64.  
  65. for (int i = 0; i < HashCrop; i++)
  66. {
  67. sb.Append(bhash[i].ToString("x2"));
  68. }
  69.  
  70. return sb.ToString();
  71. }
  72. }
  73. }
Success #stdin #stdout 0.1s 24248KB
stdin
Standard input is empty
stdout
94ee059335e587e501cc4bf90613e081