Hash table, hash algorithm, MD5 encryption algorithm first recognized

Source: Internet
Author: User
Tags md5 hash

 

In linear tables, trees, and so on, the relative positions of records in the structure are random, and there is no definite relationship between the records and the key words. Therefore, in the structure

Record is a comparison between a column and a keyword. This type of search method is based on the comparison. In the sequential search, the comparison result is = or not equal to two possibilities. in the half-query, the comparison result is less than, equal to, and greater than three possibilities for binary tree search and B-tree search. The search efficiency depends on the number of comparisons performed during the search process.

 

Ideally, if you want to obtain the queried records without any comparison, you must establish a definite relationship between the storage location of the record and Its keywords.

Ing relationship F, so that each keyword corresponds to a unique storage location in the structure. Therefore, when searching, you only need to find

F (K ),

 

If a record with the same keyword and K exists in the structure, it must be stored in the storage location of F (k). Therefore, the queried record can be directly obtained without comparison.

We call this ing relation F as a hash function, and the table created based on this idea is a hash table.

 

Computer encryption algorithm: symmetric key system, asymmetric key system, public key system, message digest, Digital Signature

Common encryption algorithms include MD5 (Message Digest) and sha1 (secure hash algorithm)

The hash values generated by these two algorithms cannot be used to calculate the original information before the operation.

The MD5 class and sha1 class are included in J2EE and can be directly used.

MessageDigest alg = null;try {alg = MessageDigest.getInstance("MD5");} catch (NoSuchAlgorithmException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}alg.update(metPassword.getText().toString().getBytes());byte[] hash = alg.digest();String strPWHash = "";for (int k = 0; k < hash.length; k++) {int v = hash[k] & 0xFF;if (v < 16)strPWHash += "0";strPWHash += Integer.toString(v, 16).toUpperCase();}        request.addProperty("strUser", metAccount.getText().toString());           request.addProperty("strPasswdHash",strPWHash);

The application encrypts the login password and sets the password set by the user to the 128-bit hash value output by MD5.

MD5 Hash function: You can enter any string of any length. After the hash function is used, a string of fixed length is returned,

Sha1y: any string whose input is smaller than the bytes bit, and the output hash value whose length is 160bit.

 

Hash function construction method: direct addressing method, digital analysis method, square method, folding method, random number method, except for the remainder (you will know this)

How to handle conflicts: key1 is not equal to key2, but F (key1) = f (key2)

Linear detection, hash, link address, and so on

 

Interview Questions

There are tens of millions of text messages, which are repeated. They are saved as text files, one line at a time, and duplicated. Use five minutes to find the first 10 records that can be repeated at most. (Do not understand)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.