public static UInt64 ToUInt64Hash(this String in_String) { // Convert the String to an array for hashing Byte[] seedStringBytes = Encoding.Unicode.GetBytes(in_String); // Create a new config in order to hash to a 64-bit number FNVConfig c = new FNVConfig() { HashSizeInBits = 64, Prime = new System.Numerics.BigInteger(1099511628211), Offset = new System.Numerics.BigInteger(14695981039346656037), }; // Compute the hash IHashValue hashValue = FNV1aFactory.Instance.Create(c).ComputeHash(seedStringBytes); if (true == BitConverter.IsLittleEndian) { return(BitConverter.ToUInt64(hashValue.Hash, 0)); } else { return(BitConverter.ToUInt64(hashValue.Hash.Reverse().ToArray(), 0)); } }
private void ComputeXxHash() { IxxHash xxHash = xxHashFactory.Instance.Create(); byte[] file = File.ReadAllBytes(Path); IHashValue hashValue = xxHash.ComputeHash(file); Hash = hashValue.AsHexString(false); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// <c>true</c> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <c>false</c>. /// </returns> public bool Equals(IHashValue other) { if (other == null || other.BitLength != BitLength) { return(false); } return(Hash.SequenceEqual(other.Hash)); }
public static HashCode32 ToHashCode32(this IHashValue hashVal, bool strictMode = true) { if (hashVal is null) { return(HashCode32.Zero); } var hex = hashVal.GetHexString(); return(strictMode ? HashCode32.Parse(hex) : HashCode32.ParseLoosely(hex)); }
public int ComputeHash(T value) { var formatter = new BinaryFormatter(); var stream = new MemoryStream(); formatter.Serialize(stream, value); byte[] result = stream.ToArray(); IHashValue hashValue = this._jenkinsOneAtATime.ComputeHash(result); return(int.Parse(hashValue.AsHexString(), System.Globalization.NumberStyles.HexNumber)); }
/// <summary> /// Get the translation (entity) for the current locale, with the default locale as a fallback. /// This method will return the given id if it could not be translated or found. /// The given <c>parameter_values</c> will get bound with the given <c>parameter_kesy</c> as external values ($-syntax), /// and will be available during the translation of the given <c>id</c>. /// </summary> /// <remarks> /// Note that the <c>id</c> can be a simple identifier or a property-expression. /// Meaning that you can have something like `foo` but also `foo.bar` or `foo.bar.baz`. /// A property expression uses the dot `.` syntax and allows you to specify values within your /// hash-tables used as values in your Entity. The default or index will be used in case a property /// identifier couldn't be found. /// For string-values this extra property identifier will simply be ignored. /// Meaning that something like `foo.bar` would be equal to `foo`. /// </remarks> public static string Translate(string id, string parameter_key_a, IHashValue parameter_value_a, string parameter_key_b, string parameter_value_b) { var keys = new List <string> { parameter_key_a, parameter_key_b }; var values = new List <L20nObject> { new Entity(parameter_value_a), new StringOutput(parameter_value_b) }; return(GetCore().Translate(id, keys, values)); }
private void NetworkChatUDP_Load(object sender, EventArgs e) { string ip = GetLocalIPAddress(); this.txtYourIP.Text = ip; //ICityHashConfig cityHashConfig = new CityHashConfig(); //ICityHash cityHash = CityHashFactory.Instance.Create(cityHashConfig); ICityHash cityHash = CityHashFactory.Instance.Create(); IHashValue hashValue32 = cityHash.ComputeHash(txtRconPassword.Text, 32); // this gives us lowercase, which is what we want txtHash.Text = hashValue32.AsHexString(); }
public static HashCode64 SafeHashCode64(this IHashValue hashVal, bool strictMode = true) { if (hashVal is null) { return(HashCode64.Zero); } var hex = hashVal.GetHexString(); return(strictMode ? HashCode64.TryParse(hex, out var hash) ? hash : HashCode64.Zero : HashCode64.TryParseLoosely(hex, out hash) ? hash : HashCode64.Zero); }
/// <summary> /// This function should be called after the L20n Initialization, but before any translation, if possible. /// Even though it's safe to call it at any time during runtime, it is not recommended. /// Globals are available to all locales and are accessible within the L20n Language via the @-syntax. /// This function stores the given <c>value</c> as a global value with the given <c>id</c> as its name. /// </summary> public static void AddComplexGlobal (string id, IHashValue value) { GetCore ().AddGlobal (id, value); }
/// <summary> /// Get the translation (entity) for the current locale, with the default locale as a fallback. /// This method will return the given id if it could not be translated or found. /// The given <c>parameter_values</c> will get bound with the given <c>parameter_kesy</c> as external values ($-syntax), /// and will be available during the translation of the given <c>id</c>. /// </summary> /// <remarks> /// Note that the <c>id</c> can be a simple identifier or a property-expression. /// Meaning that you can have something like `foo` but also `foo.bar` or `foo.bar.baz`. /// A property expression uses the dot `.` syntax and allows you to specify values within your /// hash-tables used as values in your Entity. The default or index will be used in case a property /// identifier couldn't be found. /// For string-values this extra property identifier will simply be ignored. /// Meaning that something like `foo.bar` would be equal to `foo`. /// </remarks> public static string Translate (string id, string parameter_key_a, IHashValue parameter_value_a, string parameter_key_b, string parameter_value_b) { var keys = new List<string> { parameter_key_a, parameter_key_b }; var values = new List<L20nObject> { new Entity (parameter_value_a), new StringOutput (parameter_value_b) }; return GetCore ().Translate (id, keys, values); }
public static byte[] CalculateCRC(byte[] data, ICRCConfig checksumType) { var function = CRCFactory.Instance.Create(checksumType); IHashValue value = function.ComputeHash(data); return value.Hash; }
/// <summary> /// This function should be called after the L20n Initialization, but before any translation, if possible. /// Even though it's safe to call it at any time during runtime, it is not recommended. /// Globals are available to all locales and are accessible within the L20n Language via the @-syntax. /// This function stores the given <c>value</c> as a global value with the given <c>id</c> as its name. /// </summary> public static void AddComplexGlobal(string id, IHashValue value) { GetCore().AddGlobal(id, value); }
/// <summary> /// Add a <see cref="L20nCore.External.IHashValue"/> value with the given <c>name</c>. /// </summary> public void Add(string name, IHashValue value) { // Prepare the collector var info = External.InfoCollector.Pool.GetObject(); // Collect the given value value.Collect(info); if (m_Info.Count == 0) { Internal.Logger.Warning( "can't add an external variable that has no information exposed," + " please add information by calling `Info.Add(...)`"); return; } // Add it as a child to the current object AddObject(name, info.Collect()); info.Clear(); External.InfoCollector.Pool.ReturnObject(ref info); }