天道酬勤,学无止境

hash

如何强制执行 32 位的 .net String GetHashCode() [重复](How to enforce 32bit of .net String GetHashCode() [duplicate])

问题 这个问题在这里已经有了答案: 10 年前关闭。 可能的重复: GetHashCode() 在不同的服务器上给出不同的结果? 我在我的 .net 4.0 程序中使用了字符串 GetHashCode() 并将值存储在数据库中。 问题是当我在不同的设置上运行程序时,64 vs 32,.net 使用不同的哈希算法进行字符串哈希。 所以我不会一直得到比赛。 那么有谁知道即使在 64 位构建上我如何只计算 32 位字符串散列。 回答1 简单的答案是不要这样做。 这些值被指定为平台相关的,并且在满足 GetHashCode 的契约之外没有定义确切的行为。 不能保证在 .NET 的新版本、新架构甚至补丁中都保持不变。 使用定义了行为的实际哈希算法,例如 SHA-1、CRC 或其他(取决于实际需求)。

2021-10-27 03:13:50    分类:技术分享    .net   string   hash

小字典的哈希(Hashing of small dictionary)

问题 我想散列小字典(“字典/小”)。 主文件编译正确,但在运行时它会产生带有函数insert() “分段错误”消息(特别是malloc() ,但我不知道是什么)。 哈希表 #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <ctype.h> #include <string.h> typedef struct node { char* name; struct node* next; } node; node* first[26] = {NULL}; int hash(const char* buffer) { return tolower(buffer[0]) - 'a'; } void insert(int key, const char* buffer) { node* newptr = malloc(sizeof(node)); if (newptr == NULL) { return; } strcpy(newptr->name, buffer); newptr->next = NULL; if (first[key] == NULL) { first[key] = newptr; } else { node* predptr = first[key]; while (true) {

2021-10-27 02:08:08    分类:技术分享    c   dictionary   hash   linked-list

what is algorithm hash with login control?

I use Login control and membership asp.net 4. and create user with passwrod = "12345678", my password hash in database is "h8A5hga0Cy93JsKxYnJl/U2AluU=" and passwordsalt is "UhVlqavmEX9CiKcUXkSwCw==". Then I use this code for hash password in other project: public string HashPassword(string pass, string salt) { byte[] bytes = Encoding.Unicode.GetBytes(pass); byte[] src = Encoding.Unicode.GetBytes(salt); byte[] dst = new byte[src.Length + bytes.Length]; Buffer.BlockCopy(src, 0, dst, 0, src.Length); Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length); HashAlgorithm algorithm =

2021-10-27 02:00:05    分类:问答    c#   asp.net   web-applications   hash   asp.net-membership

Getting unique hash for two different string URLs that are actually the same

I'm indexing some URLs based on their hash code and use this hash to retrieve them. I have 2 questions in this matter: Do you think this is a good approach? I mean sometimes two different URLs can produce the same hash but I don't seem to have any other choice since URLs can be very long and I need to produce a file name for them. [More important] Sometimes two different URLs are actually reffering to the same page (e.g. http://www.stackoverflow.com and http://stackoverflow.com and sometimes URLs with % characters) but I need to produce the same hash code for these URLs. What do you suggest

2021-10-27 01:50:14    分类:问答    c#   .net   string   url   hash

Ruby on Rails 2 哈希中的搜索字符串(Ruby on Rails 2 search string in Hash)

问题 我需要这方面的帮助... 我有一个这样的哈希: @ingredients = Hash.new @ingredients[1] = "Biscottes Mini(recondo)" @ingredients[2] = "Abadejo" @ingredients[3] = "Acelga" @ingredients[4] = "Agua de Coco" @ingredients[5] = "Ajo" @ingredients[6] = "Almidón de Arroz" @ingredients[7] = "Anillos Con Avena Integral cheerios (nestle)" @ingredients[8] = "Apio" 当我写“scotte”时,我需要搜索那个哈希值才能找到“Biscottes Mini(recondo)” 一些帮助? 想! 回答1 为什么在这里使用哈希而不是数组? 除了整数,您似乎没有使用其他键。 无论如何,此解决方案适用于数组和哈希: search_term = 'scotte' # you could also use find_all instead of select search_results = @ingredients.select { |key, val| val.include?(search_term)

2021-10-26 23:07:06    分类:技术分享    ruby-on-rails   ruby   search   hash

Finding Longest Substring No Duplicates - Help Optimizing Code [Ruby]

So I've been trying to solve a Leetcode Question, "Given a string, find the length of the longest substring without repeating characters." For example Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Currently I optimized my algorithm when it comes to figuring out if the substring is unique by using a hash table. However my code still runs in O(n^2) runtime, and as a result exceeds the time limit during submissions. What i try to do is to essentially go through every single possible substring and check if it has any duplicate values. Am I as efficient as it

2021-10-26 20:45:53    分类:问答    ruby   hash   substring

php preg_replace: find links and add a #hash to it?

i have the following structure... $output = '<li><a href="http://forum.example.org">Something</a></li>' Actually $output holds multiple list-items. What's the best and easiest way to apply a #hash to each links href? as in... <li><a href="http://forum.example.org#something">Something</a></li> Any idea how to solve that? edit: btw it should always be the same #hash not as you might think in this example above, the #something is equal to the name of the link. So it should be #something for each link. add_filter('wp_list_pages', 'add_hash'); /*Add #hash to wp_list_pages() function*/ function add

2021-10-26 18:44:20    分类:问答    php   hash   preg-replace

在 Rails4 中使用复选框和强参数创建多个条目(Create multiple entries with checkbox and strong params in Rails4)

问题 我遇到以下情况的问题: 我的用户通过生成列表的关键字进行搜索。 用户有 2 个操作,要么将它们添加到收藏夹表中,要么使用复选框阻止它们。 我遇到的问题是,当用户单击“添加到收藏夹”时,表单将哈希列表传递给我的强参数方法,但我无法正确传递它。 我认为问题在于 strong_params 所需的散列在另一个散列中。 我也不知道如何在用户单击“阻止”时将相同的哈希值传递给 BlockController 这是错误消息: param is missing or the value is empty: {:favorites=>{:name=>"Jon Doe", :title=>"Provider", :company=>"Acme", :location=>"Dubai", :profile=>"Group A", :notes=>""}} 我的 results.html.erb 是 <table class="table table-striped table-bordered"> <tr> <th class="center">Name</th> <th class="center">Title</th> <th class="center">Company</th> <th class="center">Location</th> <th class="center"

2021-10-26 16:11:43    分类:技术分享    ruby-on-rails   ruby-on-rails-4   hash   strong-parameters

iOS 中没有 bcrypt 实现...可以使用其他语言,创建静态库吗?(No bcrypt implementation in iOS... can use other language, create static library?)

问题 Objective-C 中没有直接的 bCrypt ( http://codahale.com/how-to-safely-store-a-password/ ) 实现,虽然有 C 代码可以实现这一点,但它专门用于 x86 处理器,依赖于 BSD 库。 我正在构建一个 iOS 应用程序,它与相应的在线(.NET 和 HTML5+Javascript)应用程序共享相同的密码哈希。 我不是很清楚我应该在哪里,在那里我可以阅读极其简单的 Java 代码 (http://www.mindrot.org/projects/jBCrypt/) 并将其转换为适用于 iOS 开发的 Objective-C 代码。 但是,有一个 Ruby 实现(https://github.com/codahale/bcrypt-ruby),我听说您可以使用 Ruby 构建 iOS 应用程序。 然后我可以将 Ruby 代码汇总到静态库中,并将其链接到我的 iOS 项目吗? 或者,甚至使用 Mono 并利用 .NET 实现(也是一个干净、纯代码、无依赖项的项目)来构建静态库? 或者,最后,有没有人知道 bCrypt 代码的 Objective-C 实现? 看起来很简单,我只是对 .NET/C#/Ruby 了解不够,无法自己翻译。 回答1 我最近开源了我自己的 BCrypt Objective C 实现。

2021-10-26 14:32:40    分类:技术分享    c#   java   objective-c   hash   bcrypt

Using PHPass to hash password trouble

I am using PHPASS to store password encrypted and compare when login. here is the code ob_start(); $userName = $password = ""; $userNameErr = $passwordErr = $loginErr = ""; $hasher = new PasswordHash(8, false); if (isset($_POST['subEmployee'])) { if (empty($_POST['user_name'])) { $userNameErr = "User name is required"; } else { $userName = check_input($_POST['user_name']); if (!preg_match("/^[0-9_a-zA-Z]*$/", $userName)) { $userNameErr = "Only letters, numbers and '_' allowed"; } } if (empty($_POST['password'])) { $passwordErr = "Password is required"; }else{ $password = check_input($_POST[

2021-10-26 11:40:29    分类:问答    php   mysql   hash   phpass