BKDR算法

@param str 字符串
@return hash值
973767
public static int bkdrHash(String str) {
		int seed = 131; // 31 131 1313 13131 131313 etc..
		int hash = 0;

		for (int i = 0; i < str.length(); i++) {
			hash = (hash * seed) + str.charAt(i);
		}

		return hash & 0x7FFFFFFF;
	}
870079
def string_hash(hash)
      hash.map { |k, v| [k.to_s, v.to_s] }.to_h
    end
1030372
public static int javaDefaultHash(String str) {
		int h = 0;
		int off = 0;
		int len = str.length();
		for (int i = 0; i < len; i++) {
			h = 31 * h + str.charAt(off++);
		}
		return h;
	}
516687
public String sha256Hex(String str) {
        byte[] a = DigestUtils.sha256(str);
        StringBuilder sb = new StringBuilder(a.length * 2);
        for(byte b: a)
            sb.append(String.format("%02x", b));
        return sb.toString();
    }
22383
public static String getHashMD5(String str) {
        try {
            return getHash(str, "MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
471346
private int getIndexOfCurlyB(String str) {
        int i;
        int j;
        i = str.indexOf("{");
        j = str.indexOf("\\{");
        while ((i - 1 == j) && (j != -1)) {
            i = str.indexOf("{", i + 1);
            j = str.indexOf("\\{", j + 1);
        }
        return i;
    }
781395
function hashThisString(string) {
    var hash = 0;
    if (string.length === 0) { return hash; }
    for (var i = 0; i < string.length; i++) {
      var char = string.charCodeAt(i);
      hash = ((hash << 5) - hash) + char;
      hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
  }
102014
def djb_hash(str, len)
      hash = 5381
      for i in (0..len) 
        hash = ((hash << 5) + hash) + str[i].to_i
      end
      return hash
    end
450873
static function str2array($str, $line_keys = null)
    {
        //切分成多行
        $lines = explode(self::$row_sep, $str);
        $result = array();
        foreach ($lines as $li)
        {
            $li = trim($li);
            if (!empty($li))
            {
                if (is_array($line_keys))
                {
                    //切分成多列
                    $data = self::parse_line($li);
                    $tmp = array();
                    foreach ($line_keys as $index => $key)
                    {
                        $tmp[$key] = $data[$index];
                    }
                    $result[] = $tmp;
                }
                else
                {
                    $result[] = self::parse_line($li);
                }
            }
        }
        return $result;
    }
485321
private static Shard createShardFromString(String str) {
    int first = str.indexOf("@");
    int second = str.indexOf("@", first + 1);
    long version = Long.parseLong(str.substring(0, first));
    String dir = str.substring(first + 1, second);
    long gen = Long.parseLong(str.substring(second + 1));
    return new Shard(version, dir, gen);
  }
944085
public static String getHashFromString(String str) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256");
            byte[] array = md.digest(str.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder();
            for (byte anArray : array) {
                sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString();
        } catch (java.security.NoSuchAlgorithmException | UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Cannot calculate SHA-256 hash for :" + str, e);
        }
    }
383714
public static byte[] decodeBytes(String str)
    {
        byte[] ret = null;

        try
        {
            // De-obfuscate the string
            if(str != null)
                ret = Base64.decodeBase64(str.getBytes());
        }
        catch(NoClassDefFoundError e)
        {
            ret = str.getBytes();
            System.out.println("WARNING: unable to decode: "
                +e.getClass().getName()+": "+e.getMessage());
        }

        return ret;
    }
1076331
private static String toSHA256String(String str) throws UnsupportedEncodingException {
    // Normalize the string before hashing.
    byte[] hash = digest.digest(toNormalizedString(str).getBytes("UTF-8"));
    StringBuilder result = new StringBuilder();
    for (byte b : hash) {
      result.append(String.format("%02x", b));
    }

    return result.toString();
  }
366535
public static int pjwHash(String str) {
		int bitsInUnsignedInt = 32;
		int threeQuarters = (bitsInUnsignedInt * 3) / 4;
		int oneEighth = bitsInUnsignedInt / 8;
		int highBits = 0xFFFFFFFF << (bitsInUnsignedInt - oneEighth);
		int hash = 0;
		int test = 0;

		for (int i = 0; i < str.length(); i++) {
			hash = (hash << oneEighth) + str.charAt(i);

			if ((test = hash & highBits) != 0) {
				hash = ((hash ^ (test >> threeQuarters)) & (~highBits));
			}
		}

		return hash & 0x7FFFFFFF;
	}
1295806
public static String fingerprint(String str) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			return byteArrayToHexString(md.digest(str.getBytes()));
		}
		catch (NoSuchAlgorithmException nsae) {
			LOGGER.warning("Unable to calculate the fingerprint for string [" + str + "].");
			return null;
		}
	}
308508
public static int jsHash(String str) {
		int hash = 1315423911;

		for (int i = 0; i < str.length(); i++) {
			hash ^= ((hash << 5) + str.charAt(i) + (hash >> 2));
		}

		return hash & 0x7FFFFFFF;
	}
61710
private int reverseHash(String str) {
    int hash = 0;
    int len = str.length();
    for (int i = 0; i < _block; i++) {
      char c = str.charAt(len - i - 1);
      hash = A * hash + CHAR_HASHES[c];
    }
    return hash;
  }