Creates color from string in form #ABC or #AABBCC, or
just simply ABC and AABBCC.
where A, B, C are hexadecimal digits.
@param hash Hash string
@return Created color or <code>null</code> in case of error
433953
public static TermColor getColorByHash(String hash) {

    	if(hash==null)
    		throw new IllegalArgumentException("Invalid hash value (null) for color construction");
    	
    	// lowercase and remove hash character, if any
    	hash = hash.toLowerCase().replaceAll("^#", "");
    	
    	// color written in #ABC format
        if(hash.matches("^[0-9a-f]{3}$")) {
            String r = hash.substring(0, 1);
            String g = hash.substring(1, 2);
            String b = hash.substring(2, 3);
            return new TermColorImpl(Integer.parseInt(r+r, 16), Integer.parseInt(g+g, 16), Integer.parseInt(b+b, 16));
        }
        // color written in #AABBCC format
        else if(hash.matches("^[0-9a-f]{6}$")) {
            String r = hash.substring(0, 2);
            String g = hash.substring(2, 4);
            String b = hash.substring(4, 6);
            return new TermColorImpl(Integer.parseInt(r, 16), Integer.parseInt(g, 16), Integer.parseInt(b, 16));
        }
        // invalid hash
        return null;
    }
479238
function string_to_color(str) {
	// Generate a Hash for the String
	var hash = function(word) {
		var h = 0;
		for (var i = 0; i < word.length; i++) {
			h = word.charCodeAt(i) + ((h << 5) - h);
		}
		return h;
	};

	// Change the darkness or lightness
	var shade = function(color, prc) {
		var num = parseInt(color, 16),
		    amt = Math.round(2.55 * prc),
		    R = (num >> 16) + amt,
		    G = (num >> 8 & 0x00FF) + amt,
		    B = (num & 0x0000FF) + amt;
		return (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
			(G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
			(B < 255 ? B < 1 ? 0 : B : 255))
			.toString(16)
			.slice(1);
	};

	// Convert init to an RGBA
	var int_to_rgba = function(i) {
		var color = ((i >> 24) & 0xFF).toString(16) +
			((i >> 16) & 0xFF).toString(16) +
			((i >> 8) & 0xFF).toString(16) +
			(i & 0xFF).toString(16);
		return color;
	};

	return shade(
		int_to_rgba(hash(str)),
		-10
	);
}
1191821
public static String createHash(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException {

    final SecureRandom random = new SecureRandom();
    final byte[] salt = new byte[SALT_BYTES];
    random.nextBytes(salt);

    final byte[] hash = pbkdf2(password, salt, PBKDF2_ITERATIONS, HASH_BYTES);
    // format iterations:salt:hash
    return PBKDF2_ITERATIONS + ":" + toHex(salt) + ":" + toHex(hash);
  }
1318607
def hash_to_styles(hash, separator = '; ')
			unless hash.empty?
				return hash.map{|e| "#{e[0]}: #{e[1].join(' ')}"}.join(separator)
			else
				return nil
			end
		end
211193
def render_hash(hsh)
      str = ""
      indiff_hsh = hsh.with_indifferent_access
      indiff_hsh.keys.sort.each do |key|
        str << "#{key}: "
        value = indiff_hsh[key]
        PP::pp(value, str)
      end
      str
    end
556502
function() {
            var randColor = (Math.random() * 0xFFFFFF << 0).toString(16);
            while (randColor.length < 6) {
                randColor = ZERO + randColor;
            }
            return HASH + randColor;
        }
221373
def stringify( hash )

            keys = @sorted ? hash.keys.sort : hash.keys
            vals = keys.map{ |key|
                val = ''
                if hash[key].kind_of?( Array ) 
                    val = rotate( hash[key] )
                elsif hash[key].kind_of?( Hash )
                    val = @sorted ? hash[key].keys.sort[0] : hash[key].keys[0]
                else
                    val = hash[key]
                end
                "#{key}: #{val}"
            }
            return vals.join( '; ' ) + (vals.length ? ';' : '')

        end
393366
def hex2rgb(h):
    
    if not h.startswith('#') or len(h) != 7:
        raise ValueError("Does not look like a hex color: '{0}'".format(h))
    return ','.join(map(str, (
        int(h[1:3], 16),
        int(h[3:5], 16),
        int(h[5:7], 16),
    )))
763876
public function setHash($hash)
    {
        if (!is_string($hash)) {
            throw new \InvalidArgumentException(
                'An invalid $hash was passed to Identicon. ' .
                'A binary string was expected.');
        }
        if (strlen($hash) < 6) {
            throw new \InvalidArgumentException(
                'An invalid $hash was passed to Identicon. ' . 
                'The hash was expected to contain at least 6 bytes.');
        }
        
        $this->hash = $hash;
        $this->value = null;
        $this->valueSet = false;
        return $this;
    }
1242611
def nscolor_from_hex(hex_string):
        

        hex_string = hex_string[1:]     # Remove leading hash
        if len(hex_string) == 3:
            hex_string = ''.join([c*2 for c in hex_string]) # 3-digit to 6-digit

        hex_int = int(hex_string, 16)
        rgb = (
            (hex_int >> 16) & 0xff,     # Red byte
            (hex_int >> 8) & 0xff,      # Blue byte
            (hex_int) & 0xff            # Green byte
        )
        rgb = [i / 255.0 for i in rgb]      # Normalize to range(0.0, 1.0)

        return AppKit.NSColor.colorWithSRGBRed_green_blue_alpha_(rgb[0], rgb[1], rgb[2], 1.0)
956144
def set_color(string, *colors)
      if colors.compact.empty?
        string
      elsif colors.all? { |color| color.is_a?(Symbol) }
        ansi_colors = colors.map { |color| lookup_color(color) }
        "#{ansi_colors.join}#{string}#{CLEAR}"
      end
    end
259176
public static Color fromHex( String hex ) {
        if (hex.startsWith("#")) {
            hex = hex.substring(1);
        }
        int length = hex.length();
        int total = 6;
        if (length < total) {
            // we have a shortened version
            String token = hex;
            int tokenLength = token.length();
            for( int i = 0; i < total; i = i + tokenLength ) {
                hex += token;
            }
        }

        int index = 0;
        String r = hex.substring(index, index + 2);
        String g = hex.substring(index + 2, index + 4);
        String b = hex.substring(index + 4, index + total);
        return new Color(Integer.valueOf(r, 16), Integer.valueOf(g, 16), Integer.valueOf(b, 16));
    }
204200
public static long decodeBase32(String hash) {
        boolean isNegative = hash.startsWith("-");
        int startIndex = isNegative ? 1 : 0;
        long base = 1;
        long result = 0;
        for (int i = hash.length() - 1; i >= startIndex; i--) {
            int j = getCharIndex(hash.charAt(i));
            result = result + base * j;
            base = base * 32;
        }
        if (isNegative)
            result *= -1;
        return result;
    }
485726
public static Color hexToColor(String hex) {
		return getColor(Integer.parseInt(StrUtil.removePrefix("#", hex), 16));
	}
1063174
public static String hash(Serializable obj) {

		if (obj == null) {
			return "";
		}
		StringBuilder hexString = new StringBuilder();
		try {

			MessageDigest m = MessageDigest.getInstance("SHA1");
			m.update(SerializationUtils.serialize(obj));

			byte[] mdbytes = m.digest();

            for (byte mdbyte : mdbytes) {
                hexString.append(Integer.toHexString(0xFF & mdbyte));
            }

		} catch (NoSuchAlgorithmException e) {
			return "";
		}
		return hexString.toString();
	}
874857
private function convertHashToArrayOfBoolean()
    {
        preg_match_all('/(\d)[\w]/', $this->hash, $matches);
        $this->color = array_map(function ($data) {
            return hexdec($data) * 16;
        }, array_reverse($matches[1]));

        return $this;
    }
1197022
public static String toHexString(long hash) {
        String hex = Long.toHexString(hash);

        if (hex.length() == 16) {
            return hex;
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0, j = 16 - hex.length(); i < j; i++) {
            sb.append('0');
        }

        return sb.append(hex).toString();
    }