githublog/rolling-your-own-crypto-aes.md at main · francisrstokes/githublog

https://github.com/google/paranoid_crypto

Paranoid project checks for well known weaknesses on cryptographic artifacts such as public keys, digital signatures and general pseudorandom numbers.

https://www.youtube.com/watch?v=S8esOtKmFDc

Python function to calculate Shannon entropy.

Non-secret text hovers around 4, truly randomstrings (compressed, encrypted, etc.) start at 5 andtop up at 8 for ASCII texts.

from math import log
def word_entropy(s: str):
	counter = dict()
	for c in s:
		if c not in counter:
			counter[c] = 0
		counter[c] += 1
		
	freqs = [counter[i] / float(len(s)) for i in counter]
	return -1 * sum([f * log(f, 2) for f in freqs])