-
Notifications
You must be signed in to change notification settings - Fork 0
/
NLFSR.pl
executable file
·60 lines (50 loc) · 1.04 KB
/
NLFSR.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Nonlinear feedback shift register implementation.
use strict;
use warnings;
my $seed='1011';
my @taps=(['0','0','0','0'],['0','0','0','1'],['0','0','1','0'],['1','1','1','0']);
my $k = 20;
###############################################
my @sr_temp = split(//,$seed);
my @coef;
my $i;
my $j;
my $z;
my $sig;
my @sig_1=();
my $sig2;
print $seed;
for ($j=0; $j<$k-@sr_temp; $j++){
#print "Sumo: ";
$sig='0';
for ($i=0; $i<@taps; $i++){
@sig_1=();
for ($z=0; $z<@{$taps[$i]}; $z++){
if ($taps[$i][$z] == '0'){push(@sig_1, '1')}
else{push(@sig_1, $sr_temp[$z])}
}
$sig2 = $sig_1[0];
for ($z=1; $z<@sig_1; $z++){
if ($sig_1[$z] == '0') {$sig2 = '0'}
}
$sig = suma($sig, $sig2);
}
print $sig;
desplaza();
}
print "\n";
sub suma{
my $uno = shift;
my $dos = shift;
if ($uno == $dos){return '0'}
else{return '1'}
}
sub desplaza{
my @temp2 = @sr_temp;
my $cont;
@sr_temp = ();
for ($cont=1; $cont<@temp2; $cont++){
push(@sr_temp,$temp2[$cont]);
}
push(@sr_temp, $sig);
}