feat: 16 funciones cybersecurity — análisis, crypto e IO de seguridad
12 funciones puras con implementación real: HashSHA256, HashMD5, EntropyShannon, IsBase64, IsHex, ExtractURLs, ParseIPCIDR, IPInRange, NormalizeURL, DetectSQLInjection, LevenshteinDistance, JaccardSimilarity 4 funciones impuras con implementación real (stdlib): LookupWhois, ResolveDNS, FetchHTTPHeaders, ScanPortTCP Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package cybersecurity
|
||||
|
||||
import "math"
|
||||
|
||||
// EntropyShannon calcula la entropia de Shannon de los datos proporcionados.
|
||||
// Devuelve un valor entre 0 (datos uniformes) y 8 (datos completamente aleatorios para bytes).
|
||||
func EntropyShannon(data []byte) float64 {
|
||||
if len(data) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var freq [256]float64
|
||||
for _, b := range data {
|
||||
freq[b]++
|
||||
}
|
||||
|
||||
n := float64(len(data))
|
||||
entropy := 0.0
|
||||
for _, f := range freq {
|
||||
if f > 0 {
|
||||
p := f / n
|
||||
entropy -= p * math.Log2(p)
|
||||
}
|
||||
}
|
||||
return entropy
|
||||
}
|
||||
Reference in New Issue
Block a user