将加密方式替换为Logistic混沌加密算法package utilimport cryptoaes cryptocipherfunc newAeadkey byte cipherAEAD error block err = aesNewCipherkey if err != nil return nil err aead err = cipherNewGCMblock if err !
package util
import ( "math" )
func logistic(r, x float64) float64 { return r * x * (1 - x) }
func logisticMap(seed, r float64, n int) []float64 { x := seed result := make([]float64, n) for i := 0; i < n; i++ { result[i] = x x = logistic(r, x) } return result }
func logisticKey(key []byte) []float64 { seed := float64(key[0]) r := float64(key[1]) return logisticMap(seed, r, len(key)) }
func xor(data []byte, key []float64) []byte { result := make([]byte, len(data)) for i := 0; i < len(data); i++ { result[i] = data[i] ^ byte(math.Floor(key[i]*256)) } return result }
func E(plain []byte, key, nonce []byte) []byte { keyStream := logisticKey(key) cipher := xor(plain, keyStream) return cipher }
func D(cipher []byte, key, nonce []byte) []byte { keyStream := logisticKey(key) plain := xor(cipher, keyStream) return plain }
原文地址: http://www.cveoy.top/t/topic/ZQd 著作权归作者所有。请勿转载和采集!