Search Results

Search found 4650 results on 186 pages for 'perfect hash'.

Page 12/186 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Efective way to avoid integer overflow when multiplying?

    - by Jonathan
    Hi, I'm working on a hash function which gets a string as input. Right now I'm doing a loop and inside the hash (an int variable) is being multiplied by a value and then the ASCII code for the current character is added to the mix. hash = hash * seed + string[i] But sometimes, if the string is big enough there is an integer overflow there, what can I do to avoid it while maintaining the same hash structure? Maybe a bit operation included inside the loop?

    Read the article

  • Using hash tables in racket

    - by user2963128
    Im working on an Ngrams program and im having trouble filling out my hash table. i want to write out a recursive function that will take the words and add them to the hash table. The way its supposed to work is given the data set 1 2 3 4 5 6 7 the first entry in the hash table should have a key of [1 2] and the data should be 3. The second entry should be: [2 3] and its data should be 4 and continuing on until the end of the text file. we are given a predefined function called readword that will simply return 1 word from the text. But im not sure how to make these calls overlap each other. The calls would look something like this if the data was hard coded in. (hash-set! (list "1" "2") 3 (hash-set! (list "2" "3") 4 2 calls that ive tried look like this (hash-set! Ngram-table(list((word1) (word2)) readword in))) (hash-set! Ngram-table(append((cdr data) word1)) readword in) apparently the in after readword is supposed to tell the computer that this is and input instead of an output or something like that. How would I call this to make the data in the key of the hashtable overlap like this? And what would the recursive call look like? edit: also we are not allowed to use assigment statements in this program.

    Read the article

  • Password hashing, salt and storage of hashed values

    - by Jonathan Leffler
    Suppose you were at liberty to decide how hashed passwords were to be stored in a DBMS. Are there obvious weaknesses in a scheme like this one? To create the hash value stored in the DBMS, take: A value that is unique to the DBMS server instance as part of the salt, And the username as a second part of the salt, And create the concatenation of the salt with the actual password, And hash the whole string using the SHA-256 algorithm, And store the result in the DBMS. This would mean that anyone wanting to come up with a collision should have to do the work separately for each user name and each DBMS server instance separately. I'd plan to keep the actual hash mechanism somewhat flexible to allow for the use of the new NIST standard hash algorithm (SHA-3) that is still being worked on. The 'value that is unique to the DBMS server instance' need not be secret - though it wouldn't be divulged casually. The intention is to ensure that if someone uses the same password in different DBMS server instances, the recorded hashes would be different. Likewise, the user name would not be secret - just the password proper. Would there be any advantage to having the password first and the user name and 'unique value' second, or any other permutation of the three sources of data? Or what about interleaving the strings? Do I need to add (and record) a random salt value (per password) as well as the information above? (Advantage: the user can re-use a password and still, probably, get a different hash recorded in the database. Disadvantage: the salt has to be recorded. I suspect the advantage considerably outweighs the disadvantage.) There are quite a lot of related SO questions - this list is unlikely to be comprehensive: Encrypting/Hashing plain text passwords in database Secure hash and salt for PHP passwords The necessity of hiding the salt for a hash Clients-side MD5 hash with time salt Simple password encryption Salt generation and Open Source software I think that the answers to these questions support my algorithm (though if you simply use a random salt, then the 'unique value per server' and username components are less important).

    Read the article

  • Javascript function to add class to a list element based on # in url.

    - by Jason
    I am trying to create a javascript function to add and remove a class to a list element based on the #tag at the end of the url on a page. The page has several different states, each with a different # in the url. I am currently using this script to change the style of a given element based on the # in the url when the user first loads the page, however if the user navigates to a different section of the page the style added on the page load stays, I would like it to change. <script type="text/javascript"> var hash=location.hash.substring(1); if (hash == 'strategy'){ document.getElementById('strategy_link').style.backgroundPosition ="-50px"; } if (hash == 'branding'){ document.getElementById('branding_link').style.backgroundPosition ="-50px"; } if (hash == 'marketing'){ document.getElementById('marketing_link').style.backgroundPosition ="-50px"; } if (hash == 'media'){ document.getElementById('media_link').style.backgroundPosition ="-50px"; } if (hash == 'management'){ document.getElementById('mangement_link').style.backgroundPosition ="-50px"; } if (hash == ''){ document.getElementById('shop1').style.display ="block"; } </script> Additionally, I am using a function to change the class of the element onClick, but when a user comes to a specific # on the page directly from another page and then clicks to a different location, two elements appear active. <script type="text/javascript"> function selectInList(obj) { $("#circularMenu").children("li").removeClass("highlight"); $(obj).addClass("highlight"); } </script> You can see this here: http://www.perksconsulting.com/dev/capabilities.php#branding Thanks.

    Read the article

  • Java HashSet using a specified method

    - by threenplusone
    I have a basic class 'HistoryItem' like so: public class HistoryItem private Date startDate; private Date endDate; private Info info; private String details; @Override public int hashCode() { int hash = (startDate == null ? 0 : startDate.hashCode()); hash = hash * 31 + (endDate == null ? 0 : endDate.hashCode()); return hash; } } I am currently using a HashSet to remove duplicates from an ArrayList on the startDate & endDate fields, which is working correctly. However I also need to remove duplicates on different fields (info & details). My question is this. Is there a way to specify a different method which HashSet will use in place of hashCode()? Something like this: public int hashCode_2() { int hash = (info == null ? 0 : info.hashCode()); hash = hash * 31 + (details == null ? 0 : details.hashCode()); return hash; } Set<HistoryItem> removeDups = new HashSet<HistoryItem>(); removeDups.setHashMethod(hashCode_2); Or is there another way that I should be doing this?

    Read the article

  • assign characters to key combinations in XP or Visual Studio .Net

    - by cpj
    I'm running Mac OSX on a MacBookPro (UK keyboard). I run windows XP under parallels in a VM. I run Visual Studio .Net 2003 and 2008 in XP in the VM when i need to. I have English United Kingdom and English United states keyboards setup in XP. (they switch sometimes for no apparent reason) There is no hash "#" key on my mac's keyboard. However, in OSX I can get a hash with an alt+3 key combination. But In Windows XP... I can not make a "#" character. I can go to the character map in windows and copy a hash.. switch into OSX and copy a hash.. search in code and copy a hash.. but I can not make a hash in XP using my keyboard without typing U+0023: ... which you can imagine is annoying. coding anything with hash symbols is becoming a choir. Anyone got any advice or key mapping tricks I can use to get hash characters working in XP using my mac UK keyboard?

    Read the article

  • Compute hash of class code at runtime (C#)?

    - by Breck Fresen
    Is it possible to compute the hash of a class at runtime in C# (presumably through reflection)? To be clear, I don't want to compute the hashcode of an instance of said class, I want to compute the hash of the class code itself (if a function in the class changes, I'd expect a different hash code to be computed). Ideally this would only be sensitive to changes in the object code (and not just a hash of the string representation of the code itself). Thanks in advance for your help, -- Breck

    Read the article

  • Ruby: How can I have a Hash take multiple keys?

    - by zxcvbnm
    I'm taking 5 strings (protocol, source IP and port, destination IP and port) and using them to store some values in a hash. The problem is that if the IPs or ports are switched between source and destination, the key is supposed to be the same. If I was doing this in C#/Java/whatever I'd have to create a new class and overwrite the hashcode()/equals() methods, but that seems error prone from the little I've read about it and I was wondering if there would be a better alternative here.

    Read the article

  • How to get the MD5 hex hash for a file using VBA?

    - by aF
    How can I get the MD5 hex hash for a file using VBA? I need a version that works for a file. Something as simple as this Python code: import hashlib def md5_for_file(fileLocation, block_size=2**20): f = open(fileLocation) md5 = hashlib.md5() while True: data = f.read(block_size) if not data: break md5.update(data) f.close() return md5.hexdigest() But in VBA.

    Read the article

  • The fundamentals of Hash tables?

    - by kylex
    I'm quite confused about the basic concepts of a Hash table. If I were to code a hash how would I even begin? What is the difference between a Hash table and just a normal array? Basically if someone answered this question I think all my questions would be answered: If I had 100 randomly generated numbers (as keys), how would I implement a hash table and why would that be advantageous over an array? Psuedo-code or Java would be appreciated as a learning tool...

    Read the article

  • How can it be impossible to "decrypt" an MD5 hash?

    - by Rob
    I was reading a question about MD5, and it made me remember something that boggles me. Very simple question, and I'm sorry if it's not a good one. I just can't understand how you convert something to one thing using some algorithm, and there being no way to convert it back using the algorithm in reverse. So how is this possible? Also, since multiple strings can create the same MD5 hash, due to it being less data than the input string, how would any other hashing system be any better?

    Read the article

  • Can you figure out the password hashing scheme?

    - by Adal
    I have two passwords and two resulting hashes. I can't figure out how the hash is derived from the password. I don't know if salting is used. I don't know if the password is hashed as a integer value or as a string (possibly Unicode). Password: 6770 Hash: c12114b91a3841c143bbeb121693e80b Password: 9591 Hash: 25238d578b6a61c2c54bfe55742984c1 The hash length seems to suggest MD5. Anybody has any ideas what I could try? Note: This is not for hacking purposes. I'm trying to access a service through an API instead of it's desktop client, and I can't figure out how to compute the password hash. Currently instead of using my real password I'm sending directly the hash.

    Read the article

  • How do I access the data in JSON converted to hash by crack in ruby?

    - by Angela
    Here is the example from the crack documentation: json = '{"posts":[{"title":"Foobar"}, {"title":"Another"}]}' Crack::JSON.parse(json) => {"posts"=>[{"title"=>"Foobar"}, {"title"=>"Another"}]} But how do I actually access the data in the hash? I've tried the following: array = Crack::JSON.parse(json) array["posts"] array["posts"] shows all the values, but I tried array["posts"]["title"] and it didn't work. Here is what I am trying to parse as an example: {"companies"=>[{"city"=>"San Mateo", "name"=>"Jigsaw", "address"=>"777 Mariners Island Blvd Ste 400", "zip"=>"94404-5059", "country"=>"USA", "companyId"=>4427170, "activeContacts"=>168, "graveyarded"=>false, "state"=>"CA"}], "totalHits"=>1} I want to access the individual elements under companies....like city and name.

    Read the article

  • How long can a hash left out in the open be considered safe?

    - by Xeoncross
    If I were to leave a SHA2 family hash out on my website - how long would it be considered safe? How long would I have before I could be sure that someone would find a collision for it and know what was hashed? I know that the amount of time would be based on the computational power of the one seeking to break it. It would also depend on the string length, but I'm curious just how secure hashes are. Since many of us run web-servers we constantly have to be prepared for the day when someone might make it all the way to the database which stores the user hashes. So, move the server security out of the way and then what do you have? This is a slightly theoretical area for many of the people I have talked with, so I would love to actually have some more information about average expectations for cracking.

    Read the article

  • Searching for range overlaps in Ruby hashes

    - by mbm
    Say you have the following Ruby hash, hash = {:a => [[1, 100..300], [2, 200..300]], :b => [[1, 100..300], [2, 301..400]] } and the following functions, def overlaps?(range, range2) range.include?(range2.begin) || range2.include?(range.begin) end def any_overlaps?(ranges) # This calls to_proc on the symbol object; it's syntactically equivalent to # ranges.sort_by {|r| r.begin} ranges.sort_by(&:begin).each_cons(2).any? do |r1, r2| overlaps?(r1, r2) end end and it's your desire to, for each key in hash, test whether any range overlaps with any other. In hash above, I would expect hash[:a] to make me mad and hash[:b] to not. How is this best implemented syntactically?

    Read the article

  • How to get the entire code of a method in memory so I can calculate its hash at runtime?

    - by bejo
    Hello stackoverflow, How to get the entire code of a method in memory so I can calculate its hash at runtime? I need to make a function like this: type TProcedureOfObject = procedure of object; function TForm1.CalculateHashValue (AMethod: TProcedureOfObject): string; var MemStream: TMemoryStream; begin result:=''; MemStream:=TMemoryStream.Create; try //how to get the code of AMethod into TMemoryStream? result:=MD5(MemStream); //I already have the MD5 function finally MemStream.Free; end; end; I use Delphi 7. Thank you.

    Read the article

  • HELP!! Delayed-job: Rake aborted! Can't modify frozen hash

    - by pmneve
    Too bad even the trace doesn't say which hash is involved. Sorry this post is long: am trying to provide enough context to be meaningful. Occurs intermittently when rake jobs:work is pulling a command out of delayed_jobs while my status observer is in the process of parsing a log file for detailed results of the previous delayed_job denizen. I have an observer class (in RAILS_ROOT/lib ) which listens for the events, makes a copy of them and calls the owner class ( in apps/models ) which then calls on the log parser (also in /lib) to do the actual work. (Should both of those classes, the observer and the parser be in app/models?) Am due to deliver this application in a few days and this is killing it (and me). Am using DirectoryWatcher to look for flag files that indicate the start and finish of the delayed_jobs. That is started at the end of environment.rb like this: require 'directory_watcher' $scriptStatusObserver = ScriptStatusObserver.new dirToWatch ="#{RAILS_ROOT}/tmp/flags" $directoryWatcher = DirectoryWatcher.new( dirToWatch ) $directoryWatcher.glob= "*.flg" $directoryWatcher.interval=(15) $directoryWatcher.add_observer( $scriptStatusObserver ) $directoryWatcher.persist=("#{RAILS_ROOT}/tmp/flags/dw_state.yml") $directoryWatcher.start at_exit { $directoryWatcher.stop } This code is outside of the run method (btw is that the best place or is inside the run better?) Here is the observer: require 'script_run' class ScriptStatusObserver def initialize @rcvdEvents = [] end def update( *events ) begin puts "#{LINE.to_s}: ScriptStatusObserver events: \n"+events.to_yaml cnt = 0 events.each do |e| if e.to_s.match(/^\s*added/) cnt = cnt + 1 @rcvdEvents << e end end ScriptRun.new.catch_up( @rcvdEvents ) if cnt > 0 @rcvdEvents.clear rescue puts $! end end end Here is ScriptRun (it attaches to an associative table built with has_many:through) require 'observer' class ScriptRun < ActiveRecord::Base set_table_name "scripts_runs" belongs_to :script belongs_to :run def parse( result ) parser = LogParser.new parser.parse(result) end def catch_up( events ) events.each do |e| typ = e.type path = e.path thisMatch = path.match(/flags\/(\d+)_(\d+)_([\d\.]+)_(\w+)\.flg/) run_id = thisMatch[1] script_id = thisMatch[2] ts = thisMatch[3] status = thisMatch[4] if e.to_s.match(/^\s*added/) status_update( script_id, run_id, status, ts, path ) end end end def status_update( script_id, run_id, status, ts, path ) scriptrun = ScriptRun.find(:first, :conditions => [ "run_id = ? and script_id = ?", run_id.to_i, script_id.to_i ]) if scriptrun.kind_of?(ScriptRun) currStatus = scriptrun.status if not currStatus == 'completed' scriptrun.update_attribute(:status, status) if status == 'parse' flag = File.new(path) logSpec = flag.gets flag.close logName = File.basename(logSpec) logPath = logSpec.sub(logName, '') logName =~ /^(([\w_]+)_([\w]+)_(\d+))\.log$/ name = $1 basename = $2 runenv = $3 tsOrPid = $4 result = Result.new result.log_path = logPath result.basename = basename result.name = name result.script_id = script_id.to_i result.run_id = run_id.to_i if runenv == 'sit' runenv = 'SIT3348' end result.application_environment_id = ApplicationEnvironment.find(:first, :conditions => [ "nodename = ?", runenv]).id parse(result) if run_completed?( run_id ) myRun = Run.find(run_id.to_i) if myRun.kind_of?( Run ) myRun.update_attribute( :completed, Time.now.to_f ) end end end end else puts "#{__LINE__.to_s}: ScriptRun.status_update: ScriptRun not found for run #{run_id} script #{script_id} ts #{ts.to_s}" end File.delete(path) end def run_completed?( id ) scriptruns = ScriptRun.find(:all, :conditions = [ "run_id = ?", id.to_i] ) scriptruns.each do |sr| if not sr.status == 'completed' return false end end return true end end LogParser is too long even for this post but it reads the script log and pulls detailed information (counts and timings) out of the log and writes to a details table. It also tallies and calculates averages and rolls those up into summary tables for quicker access from the web pages. Here is the error trace: (don't ask why everything is under my Windows profile. It's a long story) Scanner running 1270239731.43 directory_watcher.notify_observers: #, #] update:[#, /pneve/workspace/waftt-0.29/tmp/flags/100039_18_1270239550.108_parse.flg"] rake aborted! can't modify frozen hash C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/rails/activerecord/l ib/active_record/attribute_methods.rb:313:in []=' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/rails/activerecord/l ib/active_record/attribute_methods.rb:313:inwrite_attribute_without_dirty' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/rails/activerecord/l ib/active_record/dirty.rb:139:in write_attribute' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/rails/activerecord/l ib/active_record/attribute_methods.rb:211:inlast_error=' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:141:in handle_failed_job' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:115:inrun' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:162:in reserve_and_run_one_job' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:92:inwork_off' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:91:in times' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:91:inwork_off' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:66:in start' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/rails/activesupport/ lib/active_support/core_ext/benchmark.rb:10:inrealtime' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:65:in start' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:62:inloop' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/worker.rb:62:in start' C:/Documents and Settings/pneve/workspace/waftt-0.29/vendor/plugins/delayed_job/ lib/delayed/tasks.rb:13 c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:636:incall' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:636:in execute' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:631:ineach' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:631:in execute' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:597:ininvoke_with_call_chain' c:/Documents and Settings/pneve/ruby/lib/ruby/1.8/monitor.rb:242:in synchronize ' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:590:ininvoke_with_call_chain' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:583:in invoke' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2051:ininvoke_task' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2029:in top_level' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2029:ineach' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2029:in top_level' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2068:instandard_exception_handling' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2023:in top_level' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2001:inrun' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:2068:in standard_exception_handling' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake. rb:1998:inrun' c:/Documents and Settings/pneve/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake: 31 c:/Documents and Settings/pneve/ruby/bin/rake:16:in `load' c:/Documents and Settings/pneve/ruby/bin/rake:16

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >