57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
)
|
|
|
|
func main() {
|
|
// fib_lfsr()
|
|
galois_lfsr()
|
|
}
|
|
|
|
/* taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
|
|
func fib_lfsr() {
|
|
startState := uint16(0xACE1)
|
|
lfsr := startState
|
|
var bit uint16
|
|
period := uint64(0)
|
|
for {
|
|
slog.Info("fib_lfsr", "bit", fmt.Sprintf("%01b", lfsr&1), "lfsr", fmt.Sprintf("%016b", lfsr))
|
|
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1
|
|
lfsr = (lfsr >> 1) | (bit << 15)
|
|
period++
|
|
if period == 15 {
|
|
break
|
|
}
|
|
if lfsr == startState {
|
|
break
|
|
}
|
|
}
|
|
println(period)
|
|
}
|
|
|
|
/* taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
|
|
func galois_lfsr() {
|
|
startState := uint16(0xACE1)
|
|
lfsr := startState
|
|
var bit uint16
|
|
period := uint64(0)
|
|
for {
|
|
slog.Info("galois_lfsr", "bit", fmt.Sprintf("%01b", lfsr&1), "lfsr", fmt.Sprintf("%016b", lfsr))
|
|
bit = lfsr & 1
|
|
lfsr >>= 1
|
|
if bit == 1 {
|
|
lfsr ^= 0xB400
|
|
}
|
|
period++
|
|
// if period == 15 {
|
|
// break
|
|
// }
|
|
if lfsr == startState {
|
|
break
|
|
}
|
|
}
|
|
println(period)
|
|
}
|