Changeset 285 for trunk/CrypPlugins/LFSR


Ignore:
Timestamp:
Apr 11, 2009, 3:12:34 AM (13 years ago)
Author:
Sören Rinne
Message:
  • modified QuickWatchPresentation and Description
  • modified LFSR input behaviour
Location:
trunk/CrypPlugins/LFSR
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/LFSR/DetailedDescription/Description.xaml

    r272 r285  
    44
    55  <Paragraph>
    6       <Run FontWeight="Bold" FontSize="18.6666666666667" xml:lang="de-de">
    7           <Run.TextDecorations>
    8               <TextDecoration Location="Underline" />
    9           </Run.TextDecorations> LFSR (Linear Feedback Shift Register)
     6      <Run FontWeight="Bold" FontSize="14" FontFamily="Calibri" xml:lang="de-de">
     7        LFSR (Linear Feedback Shift Register)
    108      </Run>
    119  </Paragraph>
    1210  <Paragraph>
    13       <Run FontSize="14.6666666666667" xml:lang="de-de">foo</Run>
     11      <Run FontSize="11" FontFamily="Cambria" xml:lang="de-de">A linear feedback shift register (LFSR) is a shift register whose input bit is a linear function of its previous state.</Run>
    1412  </Paragraph>
    1513  <Paragraph>
    16       <Run FontSize="14.6666666666667" xml:lang="de-de">bar</Run>
     14      <Run FontSize="11" FontFamily="Cambria" xml:lang="de-de">The only linear functions of single bits are xor and inverse-xor; thus it is a shift register whose input bit is driven by the exclusive-or (xor) of some bits of the overall shift register value.</Run>
     15  </Paragraph>
     16  <Paragraph>
     17      <Run FontSize="11" FontFamily="Cambria" xml:lang="de-de">The initial value of the LFSR is called the seed, and because the operation of the register is deterministic, the stream of values produced by the register is completely determined by its current (or previous) state. Likewise, because the register has a finite number of possible states, it must eventually enter a repeating cycle. However, an LFSR with a well-chosen feedback function can produce a sequence of bits which appears random and which has a very long cycle.</Run>
     18  </Paragraph>
     19  <Paragraph>
     20      <Run FontSize="11" FontFamily="Cambria" xml:lang="de-de">Applications of LFSRs include generating pseudo-random numbers, pseudo-noise sequences, fast digital counters, and whitening sequences. Both hardware and software implementations of LFSRs are common.</Run>
    1721  </Paragraph>
    1822</FlowDocument>
  • trunk/CrypPlugins/LFSR/LFSR.cs

    r284 r285  
    257257        public void Execute()
    258258        {
     259            lFSRPresentation.DeleteAll(100);
    259260            processLFSR();
    260261        }
     
    273274                {
    274275                    GuiLogMessage("No Seed given. Aborting now.", NotificationLevel.Error);
     276                    if (!settings.UseBoolClock) inputClock.Close();
    275277                    return;
    276278                }
     
    279281                {
    280282                    GuiLogMessage("No TapSequence given. Aborting now.", NotificationLevel.Error);
     283                    if (!settings.UseBoolClock) inputClock.Close();
    281284                    return;
    282285                }
     
    286289                    // stop, because seed and tapSequence must have same length
    287290                    GuiLogMessage("ERROR - Seed and tapSequence must have same length. Aborting now.", NotificationLevel.Error);
     291                    if (!settings.UseBoolClock) inputClock.Close();
    288292                    return;
    289293                }
     
    363367                    // read stream clocks
    364368                    checkForInputClock();
     369                    inputClock.OpenWrite("LFSR Restart");
    365370                    String stringClock = inputClock.ReadByte().ToString();
    366371                    inputClock.Position = 0;
    367372                    if (String.Equals(stringClock, "49")) myClock = true; else myClock = false;
     373                    //inputClock.Close();
    368374                }
    369375
     
    525531        {
    526532            Dispose();
    527             lFSRPresentation.DeleteAll(100);
    528533        }
    529534
  • trunk/CrypPlugins/LFSR/LFSRPresentation.xaml

    r280 r285  
    33    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    44             Height="Auto" Width="Auto" Margin="0" Background="White" BorderBrush="Black" BorderThickness="1">
    5     <Grid Height="Auto" Width="Auto" Margin="0" Name="myGrid" HorizontalAlignment="Center" VerticalAlignment="Center">
    6         <Label Content="Press Play to view Presentation." Name="infoText"></Label>
     5    <Grid>
     6        <Grid Height="50" Width="Auto" Margin="5,0,0,60" Name="polynomialGrid" HorizontalAlignment="Left" VerticalAlignment="Center">
     7            <Label Name="polynomialText"></Label>
     8        </Grid>
     9        <Grid Height="Auto" Width="Auto" Margin="0,40,0,0" Name="myGrid" HorizontalAlignment="Center" VerticalAlignment="Center" />
     10        <Label Content="No Quickwatch data right now." Name="infoText" HorizontalAlignment="Center" VerticalAlignment="Center" />
    711    </Grid>
    812</UserControl>
  • trunk/CrypPlugins/LFSR/LFSRPresentation.xaml.cs

    r284 r285  
    4646                // hide initial textbox
    4747                infoText.Visibility = Visibility.Hidden;
     48                polynomialText.Visibility = Visibility.Visible;
    4849
    4950                // add lines and triangles
     
    5152                HoriLine1.X1 = 5;
    5253                HoriLine1.Y1 = 18;
    53                 HoriLine1.X2 = 180;
     54                HoriLine1.X2 = 60 + state.Length * 30;
    5455                HoriLine1.Y2 = 18;
    5556                HoriLine1.Stroke = Brushes.Black;
     
    6061                HoriLine2.X1 = 5;
    6162                HoriLine2.Y1 = 47;
    62                 HoriLine2.X2 = 150;
     63                HoriLine2.X2 = 30 + state.Length * 30;
    6364                HoriLine2.Y2 = 47;
    6465                HoriLine2.Stroke = Brushes.Black;
     
    6869                Line VertLine1 = new Line();
    6970                VertLine1.X1 = 5;
    70                 VertLine1.Y1 = 18;
     71                VertLine1.Y1 = 17.5;
    7172                VertLine1.X2 = 5;
    72                 VertLine1.Y2 = 48;
     73                VertLine1.Y2 = 47.5;
    7374                VertLine1.Stroke = Brushes.Black;
    7475                VertLine1.StrokeThickness = 1;
     
    7677
    7778                Line VertLine2 = new Line();
    78                 VertLine2.X1 = 150;
    79                 VertLine2.Y1 = 18;
    80                 VertLine2.X2 = 150;
    81                 VertLine2.Y2 = 48;
     79                VertLine2.X1 = 30 + state.Length * 30;
     80                VertLine2.Y1 = 17.5;
     81                VertLine2.X2 = 30 + state.Length * 30;
     82                VertLine2.Y2 = 47.5;
    8283                VertLine2.Stroke = Brushes.Black;
    8384                VertLine2.StrokeThickness = 1;
    8485                myGrid.Children.Add(VertLine2);
    8586
    86                 // adjust lines
    87                 HoriLine1.X2 = 60 + state.Length * 30;
    88                 HoriLine2.X2 = 30 + state.Length * 30;
    89                 VertLine2.X1 = 30 + state.Length * 30;
    90                 VertLine2.X2 = 30 + state.Length * 30;
     87                // add connection circle
     88                Ellipse ConnectionCircle = new Ellipse();
     89                ConnectionCircle.HorizontalAlignment = HorizontalAlignment.Left;
     90                ConnectionCircle.VerticalAlignment = VerticalAlignment.Top;
     91                ConnectionCircle.Fill = Brushes.Black;
     92                ConnectionCircle.Width = 4;
     93                ConnectionCircle.Height = 4;
     94                ConnectionCircle.Margin = new Thickness(27.5 + state.Length * 30, 15.5, 0, 0);
     95                myGrid.Children.Add(ConnectionCircle);
    9196
    9297                // add left triangle ////////////////////
     
    108113                    // Begin the triangle at the point specified. Notice that the shape is set to
    109114                    // be closed so only two lines need to be specified below to make the triangle.
    110                     ctx.BeginFigure(new Point(13, 14), true /* is filled */, true /* is closed */);
     115                    ctx.BeginFigure(new Point(13, 15), true /* is filled */, true /* is closed */);
    111116
    112117                    // Draw a line to the next specified point.
    113                     ctx.LineTo(new Point(13, 22), true /* is stroked */, false /* is smooth join */);
     118                    ctx.LineTo(new Point(13, 21), true /* is stroked */, false /* is smooth join */);
    114119
    115120                    // Draw another line to the next specified point.
     
    144149                    // Begin the triangle at the point specified. Notice that the shape is set to
    145150                    // be closed so only two lines need to be specified below to make the triangle.
    146                     ctx.BeginFigure(new Point(60 + state.Length * 30, 14), true /* is filled */, true /* is closed */);
     151                    ctx.BeginFigure(new Point(60 + state.Length * 30, 15), true /* is filled */, true /* is closed */);
    147152
    148153                    // Draw a line to the next specified point.
    149                     ctx.LineTo(new Point(60 + state.Length * 30, 22), true /* is stroked */, false /* is smooth join */);
     154                    ctx.LineTo(new Point(60 + state.Length * 30, 21), true /* is stroked */, false /* is smooth join */);
    150155
    151156                    // Draw another line to the next specified point.
     
    176181                {
    177182                    // add textboxes
    178                     left = (double)i * 30 + 20;
     183                    left = (double)i * 29 + 20;
    179184                    myTextBoxes[i] = new TextBox();
    180185                    myTextBoxes[i].Margin = new Thickness(left, 3, 0, 0);
     
    211216                        myEllipses[i].Name = "ellipseXOR" + i;
    212217                        myEllipses[i].Stroke = Brushes.Black;
    213                         myEllipses[i].Margin = new Thickness(7, 7, 7, 7);
     218                        myEllipses[i].Margin = new Thickness(9, 9, 9, 9);
    214219
    215220                        myLines[i] = new Line();
     
    218223                        myLines[i].StrokeThickness = 1;
    219224                        myLines[i].X1 = 15;
    220                         myLines[i].Y1 = 0;
     225                        myLines[i].Y1 = 0.5;
    221226                        myLines[i].X2 = 15;
    222                         myLines[i].Y2 = 22;
     227                        myLines[i].Y2 = 20;
    223228
    224229                        myGrids[i].Children.Add(myEllipses[i]);
     
    253258                Visual childVisual;
    254259                int i;
     260                string polynomial = "Feedback polynomial: \n";
    255261                for (i = 0; i < state.Length; i++)
    256262                {
    257263                    childVisual = (Visual)VisualTreeHelper.GetChild(myGrid, 7 + i * 2);
    258264                    childVisual.SetValue(TextBox.TextProperty, state[i].ToString());
     265                   
     266                    //build polynomial
     267                    int power;
     268                    power = (i - state.Length + 1) * -1 % state.Length;
     269                    if (tapSequence[i] == '1')
     270                    {
     271                        if (power == 1) polynomial += "x + ";
     272                        else if (power != 0) polynomial += "x^" + power + " + ";
     273                        else polynomial += "1";
     274                    }
    259275                }
    260276
     
    262278                childVisual = (Visual)VisualTreeHelper.GetChild(myGrid, 9 + (i-1) * 2);
    263279                childVisual.SetValue(Label.ContentProperty, output);
     280
     281                // update polynome
     282                childVisual = (Visual)VisualTreeHelper.GetChild(polynomialGrid, 0);
     283                childVisual.SetValue(Label.ContentProperty, polynomial);
     284
    264285            }, null);
    265286        }
     
    269290            Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    270291            {
    271                 // remove all elements except infoText beginning with the second child
    272                 myGrid.Children.RemoveRange(1, end);
     292                // remove all elements
     293                myGrid.Children.RemoveRange(0, end);
     294                polynomialText.Visibility = Visibility.Hidden;
    273295
    274296                // show initial infoText again
Note: See TracChangeset for help on using the changeset viewer.