tanszek:oktatas:techcomm:hash_functions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:techcomm:hash_functions [2024/10/07 15:23] – knehez | tanszek:oktatas:techcomm:hash_functions [2024/10/07 15:31] (current) – [Storing Passwords with Hashes] knehez | ||
---|---|---|---|
Line 24: | Line 24: | ||
Hash functions play a crucial role in cryptography by allowing us to generate a fixed-size " | Hash functions play a crucial role in cryptography by allowing us to generate a fixed-size " | ||
+ | |||
+ | ==== Task: Storing PIN Codes ==== | ||
+ | |||
+ | Consider a hypothetical ATM that allows users to withdraw money even when it’s not connected to the bank. This requires the ATM to store PIN codes locally. | ||
+ | |||
+ | But what happens if someone steals the codes from the database at night and gains access to customers' | ||
+ | |||
+ | === Example === | ||
+ | |||
+ | A customer' | ||
+ | |||
+ | 1. **Square the PIN**: | ||
+ | \[ | ||
+ | | ||
+ | \] | ||
+ | 2. Take the middle 5 digits to get a new 4-digit number: **2061**. Only the first and last two digits are retained. | ||
+ | 3. **Square again**: | ||
+ | \[ | ||
+ | | ||
+ | \] | ||
+ | 4. Take the middle 5 digits again to get another 4-digit number: **4772**. | ||
+ | 5. Repeat the squaring and digit extraction process **1000 times**. | ||
+ | 6. Suppose the final result is **6538**. | ||
+ | |||
+ | Now, what is the relationship between the initial **4531** and the resulting **6538**? It’s as if they form a pair. Even if someone knows that **6538** is the stored value and steals the database, they cannot determine which number it originated from because the digit extraction causes a loss of information that cannot be reversed or reconstructed. However, no matter how often we run the process, we always get the same result. | ||
+ | |||
+ | ==== Storing Passwords with Hashes ==== | ||
+ | |||
+ | Websites also store passwords using **hash codes**. They don’t store the actual password but transform it using an algorithm and store the result. | ||
+ | |||
+ | On some websites, you can generate various hash codes for a given password online. For example, the MD5 hash of the code '' | ||
+ | \[ | ||
+ | \text{md5}(1234) = 81dc9bdb52d04dc20036dbd8313ed055 | ||
+ | \] | ||
+ | |||
+ | Does this mean that storing hashes provides full security? Unfortunately, | ||
+ | |||
+ | Unfortunately, | ||
+ | |||
+ | === Solutions === | ||
+ | |||
+ | 1. **Use long passwords**, | ||
+ | |||
+ | 2. **Add a " | ||
+ | |||
+ | For example: | ||
+ | \[ | ||
+ | \text{md5}(1234 + \text{salt}) = 0e0db19d64ce23edc1bfb52063f25028 | ||
+ | \] | ||
+ | |||
+ | Now, try searching for this result on a hash-cracking site! | ||
+ | |||
+ | The final step is to ensure that the **salt** is well-hidden! | ||
+ |
tanszek/oktatas/techcomm/hash_functions.1728314595.txt.gz · Last modified: 2024/10/07 15:23 by knehez