{"id":19397319,"url":"https://github.com/tuxxy/entropy","last_synced_at":"2025-06-17T17:35:49.553Z","repository":{"id":43179448,"uuid":"260945406","full_name":"tuxxy/entropy","owner":"tuxxy","description":"A utility that calculates the Shannon entropy of a given input file","archived":false,"fork":false,"pushed_at":"2022-03-15T03:19:28.000Z","size":28,"stargazers_count":14,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-29T23:40:52.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuxxy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-03T14:38:30.000Z","updated_at":"2025-03-08T08:40:24.000Z","dependencies_parsed_at":"2022-09-19T09:41:18.992Z","dependency_job_id":null,"html_url":"https://github.com/tuxxy/entropy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tuxxy/entropy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuxxy%2Fentropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuxxy%2Fentropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuxxy%2Fentropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuxxy%2Fentropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuxxy","download_url":"https://codeload.github.com/tuxxy/entropy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuxxy%2Fentropy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260409102,"owners_count":23004625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T10:42:23.197Z","updated_at":"2025-06-17T17:35:44.535Z","avatar_url":"https://github.com/tuxxy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# entropy\n\n`entropy` is a tiny utility for calculating Shannon entropy of a given file.\n\n```\ntuxⒶlattice:[~] =\u003e ./entropy --help\nentropy 1.0.0\ntux \u003cme@johnpacific.com\u003e\nA utility to calculate Shannon entropy of a given file\n\nUSAGE:\n    entropy [FLAGS] \u003cfilepath\u003e\n\nARGS:\n    \u003cfilepath\u003e    The target file to measure\n\nFLAGS:\n    -h, --help              Prints help information\n    -m, --metric-entropy    Returns metric entropy instead of Shannon entropy\n    -V, --version           Prints version information\n```\n\n## Usage\n\nTo calculate the Shannon entropy of a given file, simply:\n```\ntuxⒶlattice:[~] =\u003e ./entropy path/to/file.bin\n4.142214\n```\n\nTo calculate the metric entropy of a given file, add the `--metric-entropy` flag:\n```\ntuxⒶlattice:[~] =\u003e ./entropy path/to/file.bin --metric-entropy\n0.5177767\n```\n\n## What is Shannon entropy?\n\nShannon entropy can be described as the amount of \"information\" in a string.\nIt can be calculated from the following equation:\n![Shannon Entropy Equation](https://wikimedia.org/api/rest_v1/media/math/render/svg/527fa6ed7da2d6fcfb64cc71b4fc09b4c248887a)\n\nThe output of this equation (when performed in `log_2`) can tell you the minimum\nnumber of bits required to encode a piece of \"information\" or \"symbol\" in binary form.\n\nMetric entropy is calculated by dividing the Shannon entropy with the length of\nthe symbol. Since we are calculating Shannon entropy in bits (via `log_2`) and\ncounting bytes, we divide the Shannon entropy by eight (the number of bits in a byte).\n\nThe output of metric entropy is number between 0 and 1, where 1 indicates that\nthe information (or symbols) are uniformly distributed across the string. This\ncan be used to assess how \"random\" or \"uncertain\" a particular string is. It can\nalso be an indicator that data may be effectively compressed when metric entropy\nis closer to 0.\n\n## Demonstration\n\nLet's calculate the Shannon entropy and metric entropy of a _really_ random file from `/dev/urandom`:\n```\ntuxⒶlattice:[~] =\u003e cat /dev/urandom | head -c 1000000 \u003e random.bin\n```\n\nSo we filled a 1MB file of random data from `/dev/urandom`. The data inside\nshould be uniformly distributed, but let's verify this:\n```\ntuxⒶlattice:[~] =\u003e ./entropy random.bin\n7.9998097\ntuxⒶlattice:[~] =\u003e ./entropy random.bin --metric-entropy\n0.9999762\n```\n\nAs you can see above, the Shannon entropy indicates that we need to encode each\nsymbol in the file with eight bits. The metric entropy indicates that the information\nin the `random.bin` file is uniformly distributed; it's chock-full of information!\n\nNow what happens if we do the same thing but from a file filled with all zeros? Let's find out:\n```\ntuxⒶlattice:[~] =\u003e cat /dev/zero | head -c 1000000 \u003e zero.bin\ntuxⒶlattice:[~] =\u003e ./entropy zero.bin\n0\ntuxⒶlattice:[~] =\u003e ./entropy zero.bin --metric-entropy\n0\n```\n\nThe Shannon and metric entropy is zero! Why? Because there are no unique symbols in\nthe file. The probability of finding a zero in this file is exactly 1; it's impossible\nto find a non-zero symbol in the file. Therefore, we don't need any extra information\nto encode it in a binary sequence.\n\n[For more information, see the excellent Wikipedia entry on this topic](https://en.wikipedia.org/wiki/Entropy_(information_theory)).\n\nIf this repo helped you at all, please reach out and tell me how! I'd love to hear it!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuxxy%2Fentropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuxxy%2Fentropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuxxy%2Fentropy/lists"}