entropy

Alternative Entropy Sources

荒凉一梦 提交于 2019-11-28 12:00:21
Okay, I guess this is entirely subjective and whatnot, but I was thinking about entropy sources for random number generators. It goes that most generators are seeded with the current time, correct? Well, I was curious as to what other sources could be used to generate perfectly valid, random (The loose definition) numbers. Would using multiple sources (Such as time + current HDD seek time [We're being fantastical here]) together create a "more random" number than a single source? What are the logical limits of the amount of sources? How much is really enough? Is the time chosen simply because

How to write single bits to a file in C

主宰稳场 提交于 2019-11-28 10:01:14
问题 I am programming an entropy coding algorithm and I want to write single bits like an encoded character to a file. For example I want to write 011 to a file but if you would store it as character it'd take up 3 Bytes instead of 3 Bits. So my final question is: How can I write single bits to a file? Thanks in advance! 回答1: You can't write individual bits to a file, the resolution is a single byte. If you want to write bits in sequence, you have to batch them up until you have a full byte, then

How do I compute the approximate entropy of a bit string?

不问归期 提交于 2019-11-28 04:20:23
Is there a standard way to do this? Googling -- "approximate entropy" bits -- uncovers multiple academic papers but I'd like to just find a chunk of pseudocode defining the approximate entropy for a given bit string of arbitrary length. (In case this is easier said than done and it depends on the application, my application involves 16,320 bits of encrypted data (cyphertext). But encrypted as a puzzle and not meant to be impossible to crack. I thought I'd first check the entropy but couldn't easily find a good definition of such. So it seemed like a question that ought to be on StackOverflow!

Fastest way to compute entropy in Python

爷,独闯天下 提交于 2019-11-27 17:49:54
In my project I need to compute the entropy of 0-1 vectors many times. Here's my code: def entropy(labels): """ Computes entropy of 0-1 vector. """ n_labels = len(labels) if n_labels <= 1: return 0 counts = np.bincount(labels) probs = counts[np.nonzero(counts)] / n_labels n_classes = len(probs) if n_classes <= 1: return 0 return - np.sum(probs * np.log(probs)) / np.log(n_classes) Is there a faster way? @Sanjeet Gupta answer is good but could be condensed. This question is specifically asking about the "Fastest" way but I only see times on one answer so I'll post a comparison of using scipy and

How to generate random SHA1 hash to use as ID in node.js?

时光怂恿深爱的人放手 提交于 2019-11-27 16:36:00
I am using this line to generate a sha1 id for node.js: crypto.createHash('sha1').digest('hex'); The problem is that it's returning the same id every time. Is it possible to have it generate a random id each time so I can use it as a database document id? Gabi Purcaru Have a look here: How do I use node.js Crypto to create a HMAC-SHA1 hash? I'd create a hash of the current timestamp + a random number to ensure hash uniqueness: var current_date = (new Date()).valueOf().toString(); var random = Math.random().toString(); crypto.createHash('sha1').update(current_date + random).digest('hex');

Alternative Entropy Sources

自作多情 提交于 2019-11-27 06:41:09
问题 Okay, I guess this is entirely subjective and whatnot, but I was thinking about entropy sources for random number generators. It goes that most generators are seeded with the current time, correct? Well, I was curious as to what other sources could be used to generate perfectly valid, random (The loose definition) numbers. Would using multiple sources (Such as time + current HDD seek time [We're being fantastical here]) together create a "more random" number than a single source? What are the

How to calculate the entropy of a file?

只愿长相守 提交于 2019-11-27 02:49:37
How to calculate the entropy of a file? (Or let's just say a bunch of bytes) I have an idea, but I'm not sure that it's mathematically correct. My idea is the following: Create an array of 256 integers (all zeros). Traverse through the file and for each of its bytes, increment the corresponding position in the array. At the end: Calculate the "average" value for the array. Initialize a counter with zero, and for each of the array's entries: add the entry's difference to "average" to the counter. Well, now I'm stuck. How to "project" the counter result in such a way that all results would lie

How do I compute the approximate entropy of a bit string?

[亡魂溺海] 提交于 2019-11-27 00:20:48
问题 Is there a standard way to do this? Googling -- "approximate entropy" bits -- uncovers multiple academic papers but I'd like to just find a chunk of pseudocode defining the approximate entropy for a given bit string of arbitrary length. (In case this is easier said than done and it depends on the application, my application involves 16,320 bits of encrypted data (cyphertext). But encrypted as a puzzle and not meant to be impossible to crack. I thought I'd first check the entropy but couldn't

Mutual information and joint entropy of two images - MATLAB

六月ゝ 毕业季﹏ 提交于 2019-11-26 19:40:15
I have two black and white images and I need to calculate the mutual information. Image 1 = X Image 2 = Y I know that the mutual information can be defined as: MI = entropy(X) + entropy(Y) - JointEntropy(X,Y) MATLAB already has built-in functions to calculate the entropy but not to calculate the joint entropy. I guess the true question is: How do I calculate the joint entropy of two images? Here is an example of the images I'd like to find the joint entropy of: X = 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Y = 0 0 0 0 0 0 0 0 0.38 0.82 0.38 0.04 0 0 0.32 0.82 0.68 0.17 0 0 0

How to generate random SHA1 hash to use as ID in node.js?

ぃ、小莉子 提交于 2019-11-26 18:42:38
问题 I am using this line to generate a sha1 id for node.js: crypto.createHash('sha1').digest('hex'); The problem is that it's returning the same id every time. Is it possible to have it generate a random id each time so I can use it as a database document id? 回答1: Have a look here: How do I use node.js Crypto to create a HMAC-SHA1 hash? I'd create a hash of the current timestamp + a random number to ensure hash uniqueness: var current_date = (new Date()).valueOf().toString(); var random = Math