hash

Write to a CSV file from a hash perl

∥☆過路亽.° 提交于 2020-01-01 04:46:26
问题 I have a program that at the moment reads from FILE 1 looking like the one below and matching certain characters. e.g Type, Fruit, Description, quantity tropical, banana, tasty and yummy, 5 tropical, grapefruit, bitter and not yummy, 2 ... and so on First of all I wanted to create hash of hashes for each 'Type', 'Fruit', 'Description', 'Quantity' and store the different values in the reference hashes. That works fine with the code below. use strict; use warnings; use Data::Dumper; use Text:

Generating an XML document hash in C#

廉价感情. 提交于 2020-01-01 04:46:05
问题 What's the best way to go about hashing an XML document in C#? I'd like to hash an XML document so that I can tell if it was manually changed from when it was generated. I'm not using this for security--it's OK if someone changes the XML, and changes the hash to match. For example, I'd hash the child nodes of the root and store the hash as an attribute of the root: <RootNode Hash="abc123"> <!-- Content to hash here --> </RootNode> 回答1: .NET has classes that implement the XML digital signature

turn a ruby hash into html list

偶尔善良 提交于 2020-01-01 03:10:10
问题 I'm trying to parse a yaml file like this: a: a1: a2: b: b1: b11: b2: i get a hash like this: {"a"=>{"a1"=>nil, "a2"=>nil}, "b"=>{"b1"=>{"b11"=>nil}, "b2"=>nil}} and i want to turn it to a list: %ul %li a %ul %li a1 %li a2 %li b %ul %li b1 %ul %li b11 %li b2 I'm trying to search the most efficent way doesn't matter how deep is the hash Finally i did in this way: KeyWords = %w(url) # Convert a multilevel hash into haml multilevel tree # Special KeyWords # url : item url def hash_to_haml(hash,

How to push keys and values into an empty hash w/ Ruby?

坚强是说给别人听的谎言 提交于 2020-01-01 02:26:08
问题 I have a dictionary class and want to be able to push keys (as keywords) and values (as definitions) into an empty hash with an 'add' method. I don't understand how to syntactically write that. I have included an RSPEC file too. ruby: class Dictionary attr_accessor :keyword, :definition def entries @hash = {} end def add(options) options.map do |keyword, definition| @hash[keyword.to_sym] = definition end end end Rspec: require 'dictionary' describe Dictionary do before do @d = Dictionary.new

Using mod_rewrite to convert paths with hash characters into query strings

瘦欲@ 提交于 2020-01-01 01:29:47
问题 I have a PHP project where I need to send a hash character (#) within the path of a URL. (http://www.example.com/parameter#23/parameter#67/index.php) I thought that urlencode would allow that, converting the hash to %23 But now I see that even the urlencoded hash forces the browser to treat everything to the right as the URL fragment (or query). Is there a way to pass a hash through, or do I need to do a character substitution prior to urlencode? Edit to add (Sep 19 2017): It turns out that I

Whats more random, hashlib or urandom?

て烟熏妆下的殇ゞ 提交于 2020-01-01 01:27:06
问题 I'm working on a project with a friend where we need to generate a random hash. Before we had time to discuss, we both came up with different approaches and because they are using different modules, I wanted to ask you all what would be better--if there is such a thing. hashlib.sha1(str(random.random())).hexdigest() or os.urandom(16).encode('hex') Typing this question out has got me thinking that the second method is better. Simple is better than complex. If you agree, how reliable is this

SHA256 Hash results different across Android & iOS for Big numbers

时光怂恿深爱的人放手 提交于 2019-12-31 22:39:35
问题 I'm trying to Hash a BigInteger/BigNum and I'm getting different results in Android/iOS. I need to get the same Hash result so that both the apps work as per the SRP protocol. On closer inspection it is working fine for positive numbers but not working for negative numbers (first nibble greater than 7). Not sure which one is correct and which one is to be adjusted to match with the other. Android: void hashBigInteger(String s) { try { BigInteger a = new BigInteger(s, 16); MessageDigest sha =

Calculating SHA-1 hashes in Java and C#

落花浮王杯 提交于 2019-12-31 22:29:10
问题 Calculating SHA-1 hashes in Java and C# I'm trying to replicate the logic of a Java application within a C# application. Part of this involves generating an SHA-1 hash of a password. Unfortunately I can't get the same results from Java and C#. C# Output : 64 0a b2 ba e0 7b ed c4 c1 63 f6 79 a7 46 f7 ab 7f b5 d1 fa Java Output: 164 10a b2 ba e0 17b ed c4 c1 163 f6 179 a7 146 f7 ab 17f b5 d1 fa To try and figure out what is happening I've been using the Debugger in Eclipse and Visual Studio. 1.

Android, calculating SHA-1 hash from file, fastest algorithm

自作多情 提交于 2019-12-31 21:21:21
问题 I have a problem with SHA-1 performance on Android. In C# I get calculated hash in about 3s, same calculation for Android takes about 75s. I think the problem is in reading operation from file, but I'm not sure how to improve performance. Here's my hash generation method. private static String getSHA1FromFileContent(String filename) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); //byte[] buffer = new byte[65536]; //created at start. InputStream fis = new FileInputStream

How to make “MessageDigest SHA-1 and Signature NONEwithRSA” equivalent to “Signature SHA1withRSA ”

眉间皱痕 提交于 2019-12-31 17:08:14
问题 I am interested in applying a SHA-1 hash with RSA signature to some data, but I need to do it in two steps - apply hash first and then sign the data. The Signature.sign() function appears to create a more complex (ASN.1?) data structure that is ultimately signed (see this question). How can I make the two equivalent without using any external libraries like BouncyCastle? Apply hash and sign in single step with Signature: PrivateKey privatekey = (PrivateKey) keyStore.getKey(alias, null); ...