Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. public abstract class Fnv1aBigBase : HashAlgorithm
  2. {
  3. /// <summary>
  4. /// The "wrap-around" modulo value for keeping multiplication within the number of bits.
  5. /// </summary>
  6. private readonly BigInteger modValue;
  7.  
  8. /// <summary>
  9. /// The prime.
  10. /// </summary>
  11. private readonly BigInteger fnvPrime;
  12.  
  13. /// <summary>
  14. /// The non-zero offset basis.
  15. /// </summary>
  16. private readonly BigInteger fnvOffsetBasis;
  17.  
  18. /// <summary>
  19. /// The computed hash value.
  20. /// </summary>
  21. private BigInteger hash;
  22.  
  23. protected Fnv1aBigBase(BigInteger modValue, BigInteger fnvPrime, BigInteger fnvOffsetBasis)
  24. {
  25. this.modValue = modValue;
  26. this.fnvPrime = fnvPrime;
  27. this.fnvOffsetBasis = fnvOffsetBasis;
  28. this.Initialize();
  29. }
  30.  
  31. public override sealed void Initialize()
  32. {
  33. this.hash = this.fnvOffsetBasis;
  34. }
  35.  
  36. protected override void HashCore(byte[] array, int ibStart, int cbSize)
  37. {
  38. for (var i = ibStart; i < cbSize; i++)
  39. {
  40. unchecked
  41. {
  42. this.hash ^= array[i];
  43. this.hash = (this.hash * this.fnvPrime) % this.modValue;
  44. }
  45. }
  46. }
  47.  
  48. protected override byte[] HashFinal()
  49. {
  50. return this.hash.ToByteArray();
  51. }
  52. }
  53.  
  54. public sealed class Fnv1a128 : Fnv1aBigBase
  55. {
  56. public Fnv1a128() : base(
  57. BigInteger.Parse("100000000000000000000000000000000", NumberStyles.AllowHexSpecifier),
  58. BigInteger.Parse("0000000001000000000000000000013B", NumberStyles.AllowHexSpecifier),
  59. BigInteger.Parse("6C62272E07BB014262B821756295C58D", NumberStyles.AllowHexSpecifier))
  60. {
  61. }
  62. }
  63.  
  64. public sealed class Fnv1a256 : Fnv1aBigBase
  65. {
  66. public Fnv1a256() : base(
  67. BigInteger.Parse("1000000000000000000000000000000000000000000000000000000000000000", NumberStyles.AllowHexSpecifier),
  68. BigInteger.Parse("0000000000000000000001000000000000000000000000000000000000000163", NumberStyles.AllowHexSpecifier),
  69. BigInteger.Parse("0DD268DBCAAC550362D98C384C4E576CCC8B1536847B6BBB31023B4C8CAEE0535", NumberStyles.AllowHexSpecifier))
  70. {
  71. }
  72. }
  73.  
  74. public sealed class Fnv1a512 : Fnv1aBigBase
  75. {
  76. public Fnv1a512() : base(
  77. BigInteger.Parse("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", NumberStyles.AllowHexSpecifier),
  78. BigInteger.Parse("00000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000157", NumberStyles.AllowHexSpecifier),
  79. BigInteger.Parse("0B86DB0B1171F4416DCA1E50F309990ACAC87D059C90000000000000000000D21E948F68A34C192F62EA79BC942DBE7CE182036415F56E34BAC982AAC4AFE9FD9", NumberStyles.AllowHexSpecifier))
  80. {
  81. }
  82. }
  83.  
  84. public sealed class Fnv1a1024 : Fnv1aBigBase
  85. {
  86. public Fnv1a1024() : base(
  87. BigInteger.Parse("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", NumberStyles.AllowHexSpecifier),
  88. BigInteger.Parse("000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018D", NumberStyles.AllowHexSpecifier),
  89. BigInteger.Parse("0000000000000000005F7A76758ECC4D32E56D5A591028B74B29FC4223FDADA16C3BF34EDA3674DA9A21D9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004C6D7EB6E73802734510A555F256CC005AE556BDE8CC9C6A93B21AFF4B16C71EE90B3", NumberStyles.AllowHexSpecifier))
  90. {
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement