hash

Editing JSON Array contents in Ruby

梦想的初衷 提交于 2019-12-31 03:45:32
问题 My JSON array is structured like this: {"data":[{"Chris":[{"long":10,"lat":19}]},{"Scott":[{"long":9,"lat":18}]}]} In the ruby program, I am wanting to be able to edit the lat and long values for the names. But I am not quite sure how to do so. sections.each do |user_coords| user_coords.each do |user, coords| if user == Usrname then #Change lat and long value for Usrname end end end How can this be done? 回答1: This is how to access individual elements in your JSON: require 'json' foo = JSON['{

Efficient way to hash a 2D point

你说的曾经没有我的故事 提交于 2019-12-31 03:12:08
问题 OK, so the task is this, I would be given (x, y) co-ordinates of points with both (x, y) ranging from -10^6 to 10^6 inclusive. I have to check whether a particular point e.g. (x, y) tuple was given to me or not. In simple words how do i answer the query whether a particular point(2D) is set or not. So far the best i could think of is maintaining a std::map<std::pair<int,int>, bool> and whenever a point is given I mark it 1. Although this must be running in logarithmic time and is fairly

Back end password encryption vs hashing

一曲冷凌霜 提交于 2019-12-31 01:53:13
问题 I have questions regarding the best way to secure the authentication of users. I have come across a web application that encrypts the user password in the back end . However this encryption is done with the same key to all passwords. Also, this key is "hardcoded" in the back end. They (the app developers) claim that this is perfectly secure. However I have my doubts. I believe that this method can cause two problems: The reason to encrypt passwords is to avoid access to the passwords in the

模块 hashlib 加密 签名 防篡改

淺唱寂寞╮ 提交于 2019-12-30 19:26:14
hashlib 模块 加密算法: hash (152位)散列 哈希 不可逆得 密码背后就是 hash 程序退出hash 值就变了 ,hash值得结果有可能重复 MD5 (128位) 讯息摘要演算法 基于哈希得 一种加密算法 可产生128位得散列值 (hash value) 永远都不会变 MD5功能: 1.输入任意长度的信息,经过处理,输出为128位的信息(数字指纹); 2.不同的输入得到的不同的结果(唯一性); MD5算法的特点: 压缩性:任意长度的数据,算出的MD5值的长度都是固定的 容易计算:从原数据计算出MD5值很容易 抗修改性:对原数据进行任何改动,修改一个字节生成的MD5值区别也会很大 强抗碰撞:已知原数据和MD5,想找到一个具有相同MD5值的数据(即伪造数据)是非常困难的。 MD5不可逆的原因是其是一种散列函数,使用的是hash算法,在计算过程中原文的部分信息是丢失了的。 MD5用途: 1.防止被篡改: 比如发送一个电子文档,发送前,我先得到MD5的输出结果a。然后在对方收到电子文档后,对方也得到一个MD5的输出结果b。如果a与b一样就代表中途未被篡改。 比如我提供文件下载,为了防止不法分子在安装程序中添加木马,我可以在网站上公布由安装文件得到的MD5输出结果。 SVN在检测文件是否在CheckOut后被修改过,也是用到了MD5. 2.防止直接看到明文:

Suitable hash code methods for an array of bytes?

倾然丶 夕夏残阳落幕 提交于 2019-12-30 18:31:40
问题 What is the best hash method for an array of byte ? The arrays are serialized class objects containing jpeg image passed between applications over TCP/IP. The array size is about 200k. 回答1: Any of the built-in hashing functions should do; depending on how much you care about collisions these are your options (from most collisions to least): MD5 SHA1 SHA256 SHA384 SHA512 They are as simple to use as: var hash = SHA1.Create().ComputeHash(data); Bonus Marks: If you don't care about security

Suitable hash code methods for an array of bytes?

独自空忆成欢 提交于 2019-12-30 18:31:09
问题 What is the best hash method for an array of byte ? The arrays are serialized class objects containing jpeg image passed between applications over TCP/IP. The array size is about 200k. 回答1: Any of the built-in hashing functions should do; depending on how much you care about collisions these are your options (from most collisions to least): MD5 SHA1 SHA256 SHA384 SHA512 They are as simple to use as: var hash = SHA1.Create().ComputeHash(data); Bonus Marks: If you don't care about security

Java equivalent of Perl's hash

烂漫一生 提交于 2019-12-30 17:44:02
问题 I've been using a lot Perl hashes due to super flexibility and convenient. for instance, in Perl I can do the following: $hash{AREA_CODE}->{PHONE}->{STREET_ADDR} I wondering how can I accomplish the same thing with Java, I guess it has something to do with HashMap? Thanks, 回答1: I've been using a lot Perl hashes due to super flexibility and convenient. for instance, in Perl I can do the following: $hash{AREA_CODE}->{PHONE}->{STREET_ADDR} I wondering how can I accomplish the same thing with

How to count duplicates hash itens in Ruby 1.8.5 ( Sketchup Ruby API )

喜你入骨 提交于 2019-12-30 13:37:31
问题 I need to count the duplicates, they need to be 100% identical to increase my count, but I can not use a nothing out of Ruby 1.8.5, this code will run inside a plugin in google sketchup Google Sketchup Ruby API puts VERSION 1.8.5 puts RUBY_PLATFORM i686-darwin8.10.1 product = 'Glass' x = width y = length z = density product_list = [ { "product" => 1, "x" => 200, "y" => 100, "z" => 18}, { "product" => 1, "x" => 200, "y" => 100, "z" => 18}, { "product" => 1, "x" => 300, "y" => 100, "z" => 18},

Redis——hash

让人想犯罪 __ 提交于 2019-12-30 12:33:59
KV模式不变,但V是一个键值对 K,K_V hset +key的名字:插入到hash中 例:hset user id 1 hget +key的名字:获取hash 例:hget user id hmset+key的名字+kv+kv... :一次插入多个到hash中 例:hmset customer id 1 name 张三 age 25 hmget+key的名字+k+k.... :一次获取多个 例:hmget customer id name age hgetall +key的名字:一次将key的元素全都获取 hdel +key的名字+k: 例:hdel user name 将user这个集合中name这个属性删掉 hlen +key的名字:获取hash集合长度 hexists +key的名字+k:判断key里面的某个值的key是否存在 例如:hexists customer id 返回为1 hexists customer emil 返回为0 hkeys/hvals +key的名字:获取key的所有属性/获取key的所有属性的值 例如:hkeys customer 返回 id name age hvals customer 返回 1 张三 25 hincrby/hincrbyfloat +key的名字+k:hash中数字类型属性增加值 例如:hincrby customer age

JDK1.7 的 HashMap

南楼画角 提交于 2019-12-30 12:19:09
HashMap是一个用于存储key-value的键值对集合,每个键值对都是一个Entry。这些键值对分散存储在一个数组中,这个数组就是HashMap的主干。 HashMap每个初始值都为null。 1.Put方法的原理 调用Put方法的时候发生了什么呢? 比如调用 hashMap.put("apple", 0) ,插入一个Key为“apple"的元素。这时候我们需要利用一个哈希函数来确定Entry的插入位置(index): index = Hash(“apple”) 假定最后计算出的index是2,那么结果如下: 但是,因为HashMap的长度是有限的,当插入的Entry越来越多时,再完美的Hash函数也难免会出现index冲突的情况。比如下面这样: 这时候该怎么办呢?我们可以利用 链表 来解决。 HashMap数组的每一个元素不止是一个Entry对象,也是一个链表的头节点。每一个Entry对象通过Next指针指向它的下一个Entry节点。当新来的Entry映射到冲突的数组位置时,只需要插入到对应的链表即可: 需要注意的是,新来的Entry节点插入链表时,使用的是“头插法”。至于为什么不插入链表尾部,后面会有解释。 HashMap的初始化长度16,每次自动扩容或者手动扩容长度必须是2的幂。 之前说过,从Key映射到HashMap数组的对应位置,会用到一个Hash函数: index