hash

(java) - Hash function to distribute Strings uniformly in a given range?

断了今生、忘了曾经 提交于 2021-02-19 05:22:09
问题 So ... I'm looking for a hash function that -- assuming no input skew -- will distribute nonempty Strings of (up to) 16 bytes "reasonably uniformly" onto a range [0..n] where n is user input but does not change over time. And I should be able to argue why the function should provide that "resonably uniform" distribution. In the end, all I need is a Java implementation of the hash function for use in a server and a reason "why" this hash function is suitable. So I'm looking less for "perfect

(java) - Hash function to distribute Strings uniformly in a given range?

半城伤御伤魂 提交于 2021-02-19 05:22:03
问题 So ... I'm looking for a hash function that -- assuming no input skew -- will distribute nonempty Strings of (up to) 16 bytes "reasonably uniformly" onto a range [0..n] where n is user input but does not change over time. And I should be able to argue why the function should provide that "resonably uniform" distribution. In the end, all I need is a Java implementation of the hash function for use in a server and a reason "why" this hash function is suitable. So I'm looking less for "perfect

Why would one add a constant to hashCode()? [duplicate]

懵懂的女人 提交于 2021-02-18 18:45:05
问题 This question already has answers here : Why does Java's hashCode() in String use 31 as a multiplier? (13 answers) Closed 2 years ago . I'm new to Java, and I've recently learned about hashCode() . On the wikipedia article about Java hashCode(), there is the following example of a hashCode() method: public class Employee { int employeeId; String name; Department dept; // other methods would be in here @Override public int hashCode() { int hash = 1; hash = hash * 17 + employeeId; hash = hash *

Why would one add a constant to hashCode()? [duplicate]

只愿长相守 提交于 2021-02-18 18:44:48
问题 This question already has answers here : Why does Java's hashCode() in String use 31 as a multiplier? (13 answers) Closed 2 years ago . I'm new to Java, and I've recently learned about hashCode() . On the wikipedia article about Java hashCode(), there is the following example of a hashCode() method: public class Employee { int employeeId; String name; Department dept; // other methods would be in here @Override public int hashCode() { int hash = 1; hash = hash * 17 + employeeId; hash = hash *

How to get hash value in user.config path?

情到浓时终转凉″ 提交于 2021-02-18 11:12:07
问题 I have installed .NET application. Its config location is %AppData%\[CompanyName]\[ExeName]_Url_[hash]\[version]\user.config. I need to get [hash] value from another application. According with MSDN, user.config path template is [c:\Documents and Settings]\[username]\[Local Settings]\Application Data\[companyname]\[appdomainname]_[eid]_[hash]\[version] where [hash] is SHA1 hash of evidence (in my case eid=Url). I noticed the following things: [hash] changes with application installation path

SHA algorithm generates each time unique hash string for a same key

陌路散爱 提交于 2021-02-18 03:34:26
问题 I know there are lots lots of articles available about hashing and encryption algorithm. I have figure it out from them that use hashing function instead of encryption to store password in the database . So I decided to use SHA-256 algorithm to generate hash key and I am storing that hash key into my server database instead of plain password. Now I am really not able to understand how I should use it, because each time I am passing the same password to generate SHA key it gives me different

RSA and SHA-256 encryption for signing using PHP

荒凉一梦 提交于 2021-02-16 20:26:34
问题 I'm receiving XML in request from a Web Service API. It contains a signature, signed by the requester's private key, and I have to verify it by the requester public key. Then I have to send a response with a signature, signed by my private key. This process should be done with RSA and SHA-256 in PHP. I currently have the following code: $data_to_encrypt = "MsgBody..../MsgBody"; // xml $msgbody = simplexml_load_string($data_to_encrypt); $result = $msgbody->xpath('//MsgBody'); openssl_private

RSA and SHA-256 encryption for signing using PHP

ⅰ亾dé卋堺 提交于 2021-02-16 20:25:25
问题 I'm receiving XML in request from a Web Service API. It contains a signature, signed by the requester's private key, and I have to verify it by the requester public key. Then I have to send a response with a signature, signed by my private key. This process should be done with RSA and SHA-256 in PHP. I currently have the following code: $data_to_encrypt = "MsgBody..../MsgBody"; // xml $msgbody = simplexml_load_string($data_to_encrypt); $result = $msgbody->xpath('//MsgBody'); openssl_private

Ruby getting deeply nested JSON API data

断了今生、忘了曾经 提交于 2021-02-16 16:11:17
问题 I have a rails app which gets a response from World Weather Online API. I'm using the rest-client gem and the response is in JSON format. I parse the response using: parsed_response = JSON.parse(response) Where parsed_response is obviously a hash. The data I need are strings inside a hash inside an array inside a hash inside another array inside another hash inside another hash. The inner-most nested hashes are inside ["hourly"] , an array of 8 hashes, each with 20 keys, possessing string

TCL - Parse JSON to hash/array

帅比萌擦擦* 提交于 2021-02-16 15:36:06
问题 I'm new in TCL, I have an JSON string, and I want to parse it to something I can use it easily like hash/ array which similar like in Perl or Java to loop the data and print it. But I've found many sources to help me, but it is very less and still couldn't get it. And I try something like this: #!/usr/bin/tclsh proc dict2json {dictVal} { # XXX: Currently this API isn't symmetrical, as to create proper # XXX: JSON text requires type knowledge of the input data set json "" dict for {key val}