hash

hash(hash()) vs salted hash

浪子不回头ぞ 提交于 2020-01-13 04:46:29
问题 Since the introduction of Rainbow tables, and using only hashed passwords (e.x: MD5) to stored passwords in database is not the best secured way. When people talk about salted hashes, the always use it in this way hash(password . salt) or even hash(hash(password) . salt) . I don't know why to use salt, and add extra entry for each password to store the salt? Why don't we just use hash(hash(password)) , or even hash(hash(hash(password))) ? Is it more secure to put salt? or just the sense of

hashlib,logging模块

Deadly 提交于 2020-01-13 04:22:42
hashlib 模块 作用:hash是一种算法,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法,该算法接受传入的内容,经过运算得到一串hash值 特点: 1.只要传入的内容一样,得到的hash值一样,可用于非明文密码传输时密码校验 2.不能有hash值反解成内容,既可以保证非明文密码的安全性 3.只要使用hash算法不变,无论校验的内容有多大,得到的hash值长度是固定的,可以用于文本的哈希处理, 缺陷:哈希加密算法虽然看起来很厉害,但是也存在一定的缺陷,既可以通过撞库可以反解. import hashlib m=hashlib.md5() pwd=b'123' #pwd.encode('uft8') m.update(pwd) m.hexdigest() #202cb962ac59075b964b07152d234b70 hmac模块说明:为了防止密码被撞库,我们可以使用另外一个hmac模块,它内部对我们创建key和内容做过某种处理后再加密,如果要保证hmac模块的最终结果一致,必须保证 1.hmac.new括号内指定的初始key一样 2.无论update多少次,校验的内容累加到一起是一样的内容 hmac模块 import hmac m=hmac.new(b'123') m.update(b'123') m.hexdigest()

Collision Resolution : Quadratic Probing vs. Separate Chaining

你说的曾经没有我的故事 提交于 2020-01-13 03:46:17
问题 Ok, so I've been doing some experiments with hash tables and different collision resolution problems. I'm trying to figure out which is more efficient for doing finds, a hash table that uses separate chaining or quadratic probing for collision resolution. My results suggest that separate chaining is faster than quadratic probing even for small load factors such as 0.4 or 0.2. Is this the case or are my results wrong? 回答1: The difference in processing cost between the two approaches are that

md5 hash collisions.

落花浮王杯 提交于 2020-01-12 14:26:35
问题 If counting from 1 to X, where X is the first number to have an md5 collision with a previous number, what number is X? I want to know if I'm using md5 for serial numbers, how many units I can expect to be able to enumerate before I get a collision. 回答1: Theoretically, you can expect collisions for X around 2 64 . For a hash function with an output of n bits, first collisions appear when you have accumulated about 2 n/2 outputs (it does not matter how you choose the inputs; sequential integer

md5 hash collisions.

醉酒当歌 提交于 2020-01-12 14:25:46
问题 If counting from 1 to X, where X is the first number to have an md5 collision with a previous number, what number is X? I want to know if I'm using md5 for serial numbers, how many units I can expect to be able to enumerate before I get a collision. 回答1: Theoretically, you can expect collisions for X around 2 64 . For a hash function with an output of n bits, first collisions appear when you have accumulated about 2 n/2 outputs (it does not matter how you choose the inputs; sequential integer

How can I calculate git tree hash?

好久不见. 提交于 2020-01-12 13:44:34
问题 For a nodejs project I need to determinate the hash of my folder to check the version. Actually, I made a script to test my code (without filesystem, directly of git api for my test). But it works half the time. A1 works ; A2 doesn't work because I don't get the same hash ; A3 works. A4 works. I used this API to get the hash : https://api.github.com/repos/zestedesavoir/zds-site/branches/dev I made a Perl script version to check my code js code. It returns the same things. I think my error is

Get 32-bit hash value from boost::hash

人走茶凉 提交于 2020-01-12 07:41:11
问题 I am using boost::hash to get hash value for a string. But it is giving different hash values for same string on Windows 32-bit and Debian 64-bit systems. So how can I get same hash value (32-bit or 64-bit) using boost::hash irrespective of platform? 回答1: What is the guarantee concerning boost::hash ? I don't see any guarantees that a generated hash code is usable outside of the process which generates it. (This is frequently the case with hash functions.) If you need a hash value for

How to calculate a SHA-512 hash in C++ on Linux?

ⅰ亾dé卋堺 提交于 2020-01-12 04:45:09
问题 Is there a standard library or commonly used library that can be used for calculating SHA-512 hashes on Linux? I'm looking for a C or C++ library. 回答1: Have you checked OpenSSL. I myself have not used it but documentation says it supports it. Here is list of few more implementations. Example code md = EVP_get_digestbyname("sha512"); EVP_MD_CTX_init(&mdctx); EVP_DigestInit_ex(&mdctx, md, NULL); EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); EVP

How to create a symbol from a string that has whitespaces?

假装没事ソ 提交于 2020-01-12 03:24:05
问题 I am creating a Ruby hash for movie names storage. When the hash's keys are strings that contains whitespaces, it works just fine. As in: movies = {"Avatar" => 5, "Lord of the rings" => 4, "Godfather" => 4} Now I am trying to replace the use of strings with symbols: movies = {Avatar: 5, Lord of the rings: 4, Godfather: 4} Obviously that doesn't work. How does Ruby handle whitespaces in symbol naming? 回答1: Try by yourself "Lord of the rings".to_sym #=> :"Lord of the rings" 回答2: I'm not sure

Create hash from array and frequency

时光怂恿深爱的人放手 提交于 2020-01-12 03:21:11
问题 I have an array [1,2,4,5,4,7] and I want to find the frequency of each number and store it in a hash. I have this code, but it returns NoMethodError: undefined method '+' for nil:NilClass def score( array ) hash = {} array.each{|key| hash[key] += 1} end Desired output is {1 => 1, 2 => 1, 4 => 2, 5 => 1, 7 => 1 } 回答1: Do as below : def score( array ) hash = Hash.new(0) array.each{|key| hash[key] += 1} hash end score([1,2,4,5,4,7]) # => {1=>1, 2=>1, 4=>2, 5=>1, 7=>1} Or more Rubyish using