lfsr
This commit is contained in:
parent
158ac79483
commit
e0d7914d6d
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,21 +1,6 @@
|
|||||||
# ---> Rust
|
|
||||||
# Generated by Cargo
|
|
||||||
# will have compiled files and executables
|
|
||||||
debug/
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
|
||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
|
||||||
Cargo.lock
|
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
|
||||||
**/*.rs.bk
|
|
||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# ---> Kate
|
# ---> Kate
|
||||||
# Swap Files #
|
# Swap Files #
|
||||||
.*.kate-swp
|
.*.kate-swp
|
||||||
.swp.*
|
.swp.*
|
||||||
|
|
||||||
|
*.pdf
|
||||||
|
39
main.py
Normal file
39
main.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
class lfsr(object):
|
||||||
|
def __init__(self, state, taps):
|
||||||
|
self.state = state
|
||||||
|
self.taps = taps
|
||||||
|
|
||||||
|
# getters and setters (private attributes)
|
||||||
|
def get_state(self):
|
||||||
|
return self.__state
|
||||||
|
def set_state(self, value):
|
||||||
|
self.__state = value
|
||||||
|
state = property(fget=get_state, fset=set_state, doc="lfsr state (current bits value in lfsr)")
|
||||||
|
|
||||||
|
def get_taps(self):
|
||||||
|
return self.__taps
|
||||||
|
def set_taps(self, valeur):
|
||||||
|
self.__taps = valeur
|
||||||
|
taps = property(fget=get_taps, fset=set_taps, doc="lfsr taps (bit positions affecting next state)")
|
||||||
|
|
||||||
|
def shift(self):
|
||||||
|
'''
|
||||||
|
calculate next state and return the output bit
|
||||||
|
'''
|
||||||
|
feedback = sum(self.state[tap] for tap in self.taps) % 2
|
||||||
|
output = self.state[-1]
|
||||||
|
self.state = [feedback] + self.state[:-1]
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
key=[0]*16
|
||||||
|
key.append(1)
|
||||||
|
taps = [16-0, 16-14]
|
||||||
|
|
||||||
|
lfsr17 = lfsr(key, taps)
|
||||||
|
|
||||||
|
# Generate 100 bits
|
||||||
|
for _ in range(100):
|
||||||
|
print(lfsr17.shift(), end=' ')
|
Loading…
x
Reference in New Issue
Block a user