working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,270 snippets matching: hash

    public by cghersi  290431  1  6  0

    How to simply compute the MD5 hash of a given string, being sure to have the same results retrieved by HASH method of MS SQL Server

    Returns the MD5 hash of the given string
    public static String computeMD5Hash(String input) {
    	if (isNullOrEmpty(input))
    		return "";
    	byte[] bytesOfMessage = null;
    	try {
    		bytesOfMessage = input.getBytes("UTF-16LE");
    	} catch (UnsupportedEncodingException e) {
    		log.error("Cannot support UTF-8 encoding due to " + e, e);
    		return "";
    	}
    	MessageDigest md = null;
    	try {
    		md = MessageDigest.getInstance("MD5");
    	} catch (NoSuchAlgorithmException e) {
    		log.error("Cannot support MD5 algorithm due to " + e, e);
    		return "";
    	}
    	byte[] thedigest = md.digest(bytesOfMessage);
    	return printHexByteArray(thedigest);
    }

    public by lbottaro  3061  1  8  0

    How to create a Set<T> map in java

    This simple snippet shows how to instantiate a HashSet map
    import java.util.*;
    
    public class HashSetGenerator {
        public static void main(String[] args) {
            Set<String> s = new HashSet<String>();
            for (String a : args)
                   s.add(a);
                   System.out.println(s.size() + " contains words: " + s);
        }
    }                                                

    public by lbottaro  2547  1  6  0

    How to create a Java HashMap and iterate through keys and values

    This is how to simply create a templated Map, using HashMap and loop through its keys and values
    final Map<String, Object> myMap = new HashMap<String, Object>();
            myMap.put("key1", "true");
            myMap.put("key2", "123");
    
    for (Map.Entry<String, Object> entry : myMap.entrySet())
    {
        System.out.println(entry.getKey() + "/" + entry.getValue());
    }                                                          

    public by Geometry  899  0  4  0

    DoubleDigest: Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is standard procedure in BitCoin. The resulting hash is in big endian form.

    Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is standard procedure in BitCoin. The resulting hash is in big endian form.
    using System;
    using System.Security.Cryptography;
    
    private static readonly SHA256Managed Sha256Managed;
    private static readonly SHA256Managed Sha256Managed;
    
    static Utils()
            {
                Sha256Managed = new SHA256Managed();
            }
    
    /// <summary>
    /// Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is
    /// standard procedure in BitCoin. The resulting hash is in big endian form.
    /// </summary>
    public static byte[] DoubleDigest(this byte[] input)
    {
        var first = Sha256Managed.ComputeHash(input, 0, input.Length);
        return Sha256Managed.ComputeHash(first);
    }

    public by snip2code  22968  23  7  9

    Compute MD5 Hash in C#

    Returns an hash (computed with MD5 algorithm) of the given string. Note: this is compliant with the results given by HashBytes('MD5', @text) method of SQL Server.
    public static string ComputeMD5HashSQLServerCompliant(this string password)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] binaryInput = Encoding.Unicode.GetBytes(password);
        byte[] hashOfInput = md5.ComputeHash(binaryInput);
        return hashOfInput.PrintHexByteArray();
    }
    
    

    public by Geometry  88737  0  5  0

    FromText: Creates a new CsvReader to read from a string.

    Creates a new CsvReader to read from a string. The text containing the fields in the CSV format. if field names are located on the first non commented line, otherwise, .
    /// <summary>
    ///   Creates a new CsvReader to read from a string.
    /// </summary>
    /// 
    /// <param name="text">The text containing the fields in the CSV format.</param>
    /// <param name="hasHeaders"><see langword="true"/> if field names are located on the first non commented line, otherwise, <see langword="false"/>.</param>
    /// 
    public static CsvReader FromText(string text, bool hasHeaders)
    {
        return new CsvReader(new StringReader(text), hasHeaders, text.Length);
    }

    public by sTiLL-iLL @ SniPitz-KND  4177  2  7  19

    Try this HashMap! ++ ++ ++

    hash-table and key generator,.. uuids, cool extedo method, oh yeah, it also supports using objects as keys!!!
    ///////////////////////////
    // unique ids puhleez!!! //
    ///////////////////////////
    
    function nextUid() {
      var index = uid.length;
      var digit;
    
      while(index) {
        index--;
        digit = uid[index].charCodeAt(0);
        if (digit == 57 /*'9'*/) {
          uid[index] = 'A';
          return uid.join('');
        }
        if (digit == 90  /*'Z'*/) {
          uid[index] = '0';
        } else {
          uid[index] = String.fromCharCode(digit + 1);
          return uid.join('');
        }
      }
      uid.unshift('0');
      return uid.join('');
    }
    
    /////////////////////////////////////////////
    // Set or clear the hashkey for an object. //
    ////////////////////////////////////////////
    
    function setHashKey(obj, h) {
      if (h) {
        obj.$$hashKey = h;
      }
      else {
        delete obj.$$hashKey;
      }
    }
    
    function extend(dest) {
      var h = dst.$$hashKey;
      forEach(arguments, function(obj){
        if (obj !== dest) {
          forEach(obj, function(value, key){
            dest[key] = value;
          });
        }
      });
      setHashKey(dest,h);
      return dset;
    }
    
    function int(str) {
      return parseInt(str, 10);
    }
    
    
    function inherit(parent, extra) {
      return extend(new (extend(function() {},
        { prototype:parent })
      )(), extra);
    }
    
    ///////////////////////////////
       // Heath'sHash(map) //
       // keys & values //
     //////////////////////////////
    
    function hashKey(obj) {
      var objType = typeof obj,
          key;
    
      if (objType == 'object' && obj !== null) {
        if (typeof (key = obj.$$hashKey) == 'function') {
          // must invoke on object to keep the right this
          key = obj.$$hashKey();
        } else if (key === undefined) {
          key = obj.$$hashKey = nextUid();
        }
      } else {
        key = obj;
      }
    
      return objType + ':' + key;
    }
    
    ////////////////////////////////////////////
     
    function HashMap(array){
      forEach(array, this.put, this);
    }
    
    HashMap.prototype = {
      put: function(key, value) {
        this[hashKey(key)] = value;
      },
      get: function(key) {
        return this[hashKey(key)];
      },
      remove: function(key) {
        var value = this[key = hashKey(key)];
        delete this[key];
        return value;
      }
    };
                

    public by Geometry  620  0  4  0

    HashCoinbase: Hashes the coinbase.

    Hashes the coinbase.
    using System;
    using System.IO;
    using System.Linq;
    using CoiniumServ.Coin.Address;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using CoiniumServ.Utils.Extensions;
    using CoiniumServ.Utils.Numerics;
    using Gibbed.IO;
    using Serilog;
    
    /// <summary>
    /// Hashes the coinbase.
    /// </summary>
    /// <param name="coinbase"></param>
    /// <param name="doubleDigest"></param>
    /// <returns></returns>
    public static Hash HashCoinbase(byte[] coinbase, bool doubleDigest = true)
    {
        return doubleDigest ? coinbase.DoubleDigest() : coinbase.Digest();
    
        // TODO: fix this according - https://github.com/zone117x/node-stratum-pool/blob/eb4b62e9c4de8a8cde83c2b3756ca1a45f02b957/lib/jobManager.js#L69
    }

    public by Geometry  1326  1  4  0

    GetReadableHashrate: Returns given hashrate value as human readable string.

    Returns given hashrate value as human readable string.
    using System;
    using System.Globalization;
    
    /// <summary>
    /// Returns given hashrate value as human readable string.
    /// </summary>
    /// <param name="hashrate"></param>
    /// <returns></returns>
    public static string GetReadableHashrate(this UInt64 hashrate)
    {
        var index = -1;
        double rate = hashrate;
    
        var units = new[] {"KH/s", "MH/s", "GH/s", "TH/s", "PH/s", "EH/s", "ZH/s", "YH/s"};
    
        do
        {
            rate = rate/1000;
            index++;
        } while (rate > 1000);
    
        return string.Format("{0:0.00} {1}", rate, units[index]);
    }

    public by lauhin  2908  0  6  0

    Unit test equals and hashcode

    how to unit test equals and hashcode from a class in java
    //maven dependency
    <dependency>
        <groupId>nl.jqno.equalsverifier</groupId>
        <artifactId>equalsverifier</artifactId>
        <version>1.1.3</version>
    </dependency>
    
    //unit test method
    @Test
    public void testEqualsAndHashcode() {
        EqualsVerifier.forClass(ModelClassToTest.class).usingGetClass().suppress(Warning.NONFINAL_FIELDS).verify();
    }                       
    • Public Snippets
    • Channels Snippets