hash

Hash of unique value = unique hash?

回眸只為那壹抹淺笑 提交于 2020-01-01 17:12:24
问题 Theoretically does hashing a unique value yield a unique value? Let's say I have a DB table with 2 columns: id and code. id is an auto-incrementing int and code is a varchar. If I do ... $code = sha1($id); ... and then store $code into the same row as $id. Will my code column be unique as well? What about if I append the current time? eg: $code = sha1($id . time()); Thanks. 回答1: In general, the answer is no. This is trivial to show: SHA-1 has 2^160 different outputs - 160 bits, but there are

java集合HashMap、HashTable、HashSet详解

99封情书 提交于 2020-01-01 14:55:55
一、Set和Map关系 Set代表集合元素无序,集合元素不可重复的集合,Map代表一种由多个key-value组成的集合,map集合是set集合的扩展只是名称不同,对应如下 二、HashMap的工作原理 HashMap基于 hashing原理 ,通过put()和get()方法储存和获取对象。 put()方法: 它调用键对象的hashCode()方法来计算hashcode值,系统根据hashcode值决定该元素在bucket位置。如果两个对象key的hashcode返回值相同,那他们的存储位置相同,如果这两个Entry的key通过equals比较返回true,新添加Entry的value将覆盖集合中原有Entry的value,但key不会覆盖;如果这两个Entry的key通过equals比较返回false,新添加的Entry将与集合中原有Entry形成Entry链,而且新添加Entry位于Entry链的头部。put源码如下: public V put(K paramK, V paramV) { //如果key为空,调用putForNullKey方法 if (paramK == null) return putForNullKey(paramV); //根据key的keyCode计算Hash值 int i = hash(paramK.hashCode()); /

Internet History,Technology and Security

徘徊边缘 提交于 2020-01-01 14:31:30
Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Communication 二战期间,需要有效快速的方式联系盟国,进而意味着通信方式需要便捷以及快速。 但是无线通信难以物理隐藏,需要利用code(应该是密码)来加密解密,也就产生了相应的计算需求,数学则是其中重要的工具。 为了破解这类code,选择借助于计算机,从最早的机械计算机(mechanical computer)利用暴力枚举的方式破解。在面对复杂度较高的密码时,破解时间过长导致的延误,使得当时迫切的需要新的电子计算机(electronic computer)。 the moment where a mechanical computer,no matter how hard you tried,wouldn't work fast enough Computer in Phone line 战后,对于计算机更倾向于将其通用化,利用其高效的计算能力去满足多方面的需求。 当时,各个计算机利用调制解调器(modem)来相互连接通信,但是它低效,慢速而且昂贵。 Q:为什么战时选择实现无线通信,而战后时间内还是一直采用利用有线来构建通信方式? 不过那个电传打字机还是蛮有趣的。 Second

Is this an appropriate login and registration encryption system

旧巷老猫 提交于 2020-01-01 12:25:34
问题 Apparently, hashing the username and password and saving them as cookies and logging in with sanitized cookie data is not good enough for you people (or my site's safety). Is this approach good enough? Registration procedure: $salt= date('U'); $username= hash('sha256', $salt. $_POST['username']); $password= hash('sha256', $salt. $_POST['password']); $token = hash('sha256', $salt. (rand(1,10000000000000000000000000000000000000000000))); To login manually, users type in their username and

fast loading of large hash table in Perl

百般思念 提交于 2020-01-01 12:09:09
问题 I have about 30 text files with the structure wordleft1|wordright1 wordleft2|wordright2 wordleft3|wordright3 ... The total size of the files is about 1 GB with about 32 million lines of word combinations. I tried a few approaches to load them as fast as possible and store the combinations within a hash $hash{$wordleft} = $wordright Opening file by file and reading line by line takes about 42 seconds. I then store the hash with the Storable module store \%hash, $filename Loading the data again

HashMap、lru、散列表

北战南征 提交于 2020-01-01 10:21:05
HashMap HashMap的数据结构:HashMap实际上是一个数组和链表(“链表散列”)的数据结构。底层就是一个数组结构,数组中的每一项又是一个链表。 hashCode是一个对象的标识,Java中对象的hashCode是一个int类型值。通过hashCode来算出指定数组的索引可以快速定位到要找的对象在数组中的位置,之后再遍历链表找到对应值,理想情况下时间复杂度为O(1),并且不同对象可以拥有相同的hashCode(hash碰撞)。发生碰撞后会把相同hashcode的对象放到同一个链表里,但是在数组大小不变的情况下,存放键值对越多,查找的时间效率也会降低 扩容可以解决该问题,而负载因子决定了什么时候扩容,负载因子是已存键值对的数量和总的数组长度的比值。默认情况下负载因子为0.75,我们可在初始化HashMap的时候自己修改。阀值 = 当前数组长度✖负载因子 hashmap中默认负载因子为0.75,长度默认是16,默认情况下第一次扩容判断阀值是16 ✖ 0.75 = 12;所以第一次存键值对的时候,在存到第13个键值对时就需要扩容了,变成16X2=32。 put流程 对key hash,二次hash,hash扰乱函数,减少hash碰撞 int hash(Object key) { int h = key.hashCode(); return (h ^ (h >>> 16)) &

Search for hash in an array by value

旧街凉风 提交于 2020-01-01 10:06:14
问题 I have a function which extracts Excel data into an array of hashes like so: sub set_exceldata { my $excel_file_or = '.\Excel\ORDERS.csv'; if (-e $excel_file_or) { open (EXCEL_OR, $excel_file_or) || die("\n can't open $excel_file_or: $!\n"); while () { chomp; my ( $id, $date, $product, $batchid, $address, $cost ) = split ","; my %a = ( id => $id , date => $date , product => $product , batchid => $batchid , address => $address , cost => $cost ); push ( @array_data_or, \%a ); } close EXCEL_OR;

PHP - hash_pbkdf2 function

最后都变了- 提交于 2020-01-01 09:55:12
问题 I'm trying to do a function to hash passwords with this php function: http://be.php.net/manual/en/function.hash-pbkdf2.php. Here is the code: $hash_algo = "sha256"; $password = "password"; $salt = "salt"; $iterations = 1; $length = 1; $raw_output = false; $hash = hash_pbkdf2($hash_algo, $password, $salt, $iterations ,$length ,$raw_output); echo $hash; I got this error: Fatal error: Call to undefined function hash_pbkdf2(). How can the function be undefined??? PS: All the values of my

Can I use an already MD5 encoded password in Digest Authentication

僤鯓⒐⒋嵵緔 提交于 2020-01-01 09:44:31
问题 I have MD5 hashes of passwords in a database that I want to use against HTTP AUTH DIGEST. But in reading the docs, it looks like the digest hash contains a hash of the username,realm and plaintext password. Is there any way to use the MD5 hash of the password in this situation? 回答1: No. If the hash they need is generated like so: MD5(username + realm + password) You are out of luck. If they are hashing the password like so: MD5(MD5(password) + username + realm) You'd be able to do that with

MySQL Hash Indexes for Optimization

感情迁移 提交于 2020-01-01 09:37:07
问题 So maybe this is noob, but I'm messing with a couple tables. I have TABLE A roughly 45,000 records I have TABLE B roughly 1.5 million records I have a query: update schema1.tablea a inner join ( SELECT DISTINCT ID, Lookup, IDpart1, IDpart2 FROM schema1.tableb WHERE IDpart1 is not NULL AND Lookup is not NULL ORDER BY ID,Lookup ) b Using(ID,Lookup) set a.Elg_IDpart1 = b.IDpart1, a.Elg_IDpart2 = b.IDpart2 where a.ID is NOT NULL AND a.Elg_IDpart1 is NULL So I am forcing the index on ID, Lookup.