Changeset 863 for trunk/CrypPlugins/MD5


Ignore:
Timestamp:
Nov 17, 2009, 4:28:43 PM (12 years ago)
Author:
pretzsch
Message:

+ MD5 plugin: Presentation prototype
o MD5 plugin: Refactoring

Location:
trunk/CrypPlugins/MD5
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/MD5/MD5.cs

    r853 r863  
    1 /*                              Apache License
    2                            Version 2.0, January 2004
    3                         http://www.apache.org/licenses/
    4 
    5    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    6 
    7    1. Definitions.
    8 
    9       "License" shall mean the terms and conditions for use, reproduction,
    10       and distribution as defined by Sections 1 through 9 of this document.
    11 
    12       "Licensor" shall mean the copyright owner or entity authorized by
    13       the copyright owner that is granting the License.
    14 
    15       "Legal Entity" shall mean the union of the acting entity and all
    16       other entities that control, are controlled by, or are under common
    17       control with that entity. For the purposes of this definition,
    18       "control" means (i) the power, direct or indirect, to cause the
    19       direction or management of such entity, whether by contract or
    20       otherwise, or (ii) ownership of fifty percent (50%) or more of the
    21       outstanding shares, or (iii) beneficial ownership of such entity.
    22 
    23       "You" (or "Your") shall mean an individual or Legal Entity
    24       exercising permissions granted by this License.
    25 
    26       "Source" form shall mean the preferred form for making modifications,
    27       including but not limited to software source code, documentation
    28       source, and configuration files.
    29 
    30       "Object" form shall mean any form resulting from mechanical
    31       transformation or translation of a Source form, including but
    32       not limited to compiled object code, generated documentation,
    33       and conversions to other media types.
    34 
    35       "Work" shall mean the work of authorship, whether in Source or
    36       Object form, made available under the License, as indicated by a
    37       copyright notice that is included in or attached to the work
    38       (an example is provided in the Appendix below).
    39 
    40       "Derivative Works" shall mean any work, whether in Source or Object
    41       form, that is based on (or derived from) the Work and for which the
    42       editorial revisions, annotations, elaborations, or other modifications
    43       represent, as a whole, an original work of authorship. For the purposes
    44       of this License, Derivative Works shall not include works that remain
    45       separable from, or merely link (or bind by name) to the interfaces of,
    46       the Work and Derivative Works thereof.
    47 
    48       "Contribution" shall mean any work of authorship, including
    49       the original version of the Work and any modifications or additions
    50       to that Work or Derivative Works thereof, that is intentionally
    51       submitted to Licensor for inclusion in the Work by the copyright owner
    52       or by an individual or Legal Entity authorized to submit on behalf of
    53       the copyright owner. For the purposes of this definition, "submitted"
    54       means any form of electronic, verbal, or written communication sent
    55       to the Licensor or its representatives, including but not limited to
    56       communication on electronic mailing lists, source code control systems,
    57       and issue tracking systems that are managed by, or on behalf of, the
    58       Licensor for the purpose of discussing and improving the Work, but
    59       excluding communication that is conspicuously marked or otherwise
    60       designated in writing by the copyright owner as "Not a Contribution."
    61 
    62       "Contributor" shall mean Licensor and any individual or Legal Entity
    63       on behalf of whom a Contribution has been received by Licensor and
    64       subsequently incorporated within the Work.
    65 
    66    2. Grant of Copyright License. Subject to the terms and conditions of
    67       this License, each Contributor hereby grants to You a perpetual,
    68       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    69       copyright license to reproduce, prepare Derivative Works of,
    70       publicly display, publicly perform, sublicense, and distribute the
    71       Work and such Derivative Works in Source or Object form.
    72 
    73    3. Grant of Patent License. Subject to the terms and conditions of
    74       this License, each Contributor hereby grants to You a perpetual,
    75       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    76       (except as stated in this section) patent license to make, have made,
    77       use, offer to sell, sell, import, and otherwise transfer the Work,
    78       where such license applies only to those patent claims licensable
    79       by such Contributor that are necessarily infringed by their
    80       Contribution(s) alone or by combination of their Contribution(s)
    81       with the Work to which such Contribution(s) was submitted. If You
    82       institute patent litigation against any entity (including a
    83       cross-claim or counterclaim in a lawsuit) alleging that the Work
    84       or a Contribution incorporated within the Work constitutes direct
    85       or contributory patent infringement, then any patent licenses
    86       granted to You under this License for that Work shall terminate
    87       as of the date such litigation is filed.
    88 
    89    4. Redistribution. You may reproduce and distribute copies of the
    90       Work or Derivative Works thereof in any medium, with or without
    91       modifications, and in Source or Object form, provided that You
    92       meet the following conditions:
    93 
    94       (a) You must give any other recipients of the Work or
    95           Derivative Works a copy of this License; and
    96 
    97       (b) You must cause any modified files to carry prominent notices
    98           stating that You changed the files; and
    99 
    100       (c) You must retain, in the Source form of any Derivative Works
    101           that You distribute, all copyright, patent, trademark, and
    102           attribution notices from the Source form of the Work,
    103           excluding those notices that do not pertain to any part of
    104           the Derivative Works; and
    105 
    106       (d) If the Work includes a "NOTICE" text file as part of its
    107           distribution, then any Derivative Works that You distribute must
    108           include a readable copy of the attribution notices contained
    109           within such NOTICE file, excluding those notices that do not
    110           pertain to any part of the Derivative Works, in at least one
    111           of the following places: within a NOTICE text file distributed
    112           as part of the Derivative Works; within the Source form or
    113           documentation, if provided along with the Derivative Works; or,
    114           within a display generated by the Derivative Works, if and
    115           wherever such third-party notices normally appear. The contents
    116           of the NOTICE file are for informational purposes only and
    117           do not modify the License. You may add Your own attribution
    118           notices within Derivative Works that You distribute, alongside
    119           or as an addendum to the NOTICE text from the Work, provided
    120           that such additional attribution notices cannot be construed
    121           as modifying the License.
    122 
    123       You may add Your own copyright statement to Your modifications and
    124       may provide additional or different license terms and conditions
    125       for use, reproduction, or distribution of Your modifications, or
    126       for any such Derivative Works as a whole, provided Your use,
    127       reproduction, and distribution of the Work otherwise complies with
    128       the conditions stated in this License.
    129 
    130    5. Submission of Contributions. Unless You explicitly state otherwise,
    131       any Contribution intentionally submitted for inclusion in the Work
    132       by You to the Licensor shall be under the terms and conditions of
    133       this License, without any additional terms or conditions.
    134       Notwithstanding the above, nothing herein shall supersede or modify
    135       the terms of any separate license agreement you may have executed
    136       with Licensor regarding such Contributions.
    137 
    138    6. Trademarks. This License does not grant permission to use the trade
    139       names, trademarks, service marks, or product names of the Licensor,
    140       except as required for reasonable and customary use in describing the
    141       origin of the Work and reproducing the content of the NOTICE file.
    142 
    143    7. Disclaimer of Warranty. Unless required by applicable law or
    144       agreed to in writing, Licensor provides the Work (and each
    145       Contributor provides its Contributions) on an "AS IS" BASIS,
    146       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    147       implied, including, without limitation, any warranties or conditions
    148       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
    149       PARTICULAR PURPOSE. You are solely responsible for determining the
    150       appropriateness of using or redistributing the Work and assume any
    151       risks associated with Your exercise of permissions under this License.
    152 
    153    8. Limitation of Liability. In no event and under no legal theory,
    154       whether in tort (including negligence), contract, or otherwise,
    155       unless required by applicable law (such as deliberate and grossly
    156       negligent acts) or agreed to in writing, shall any Contributor be
    157       liable to You for damages, including any direct, indirect, special,
    158       incidental, or consequential damages of any character arising as a
    159       result of this License or out of the use or inability to use the
    160       Work (including but not limited to damages for loss of goodwill,
    161       work stoppage, computer failure or malfunction, or any and all
    162       other commercial damages or losses), even if such Contributor
    163       has been advised of the possibility of such damages.
    164 
    165    9. Accepting Warranty or Additional Liability. While redistributing
    166       the Work or Derivative Works thereof, You may choose to offer,
    167       and charge a fee for, acceptance of support, warranty, indemnity,
    168       or other liability obligations and/or rights consistent with this
    169       License. However, in accepting such obligations, You may act only
    170       on Your own behalf and on Your sole responsibility, not on behalf
    171       of any other Contributor, and only if You agree to indemnify,
    172       defend, and hold each Contributor harmless for any liability
    173       incurred by, or claims asserted against, such Contributor by reason
    174       of your accepting any such warranty or additional liability.
    175 
    176    END OF TERMS AND CONDITIONS
    177 
    178    APPENDIX: How to apply the Apache License to your work.
    179 
    180       To apply the Apache License to your work, attach the following
    181       boilerplate notice, with the fields enclosed by brackets "[]"
    182       replaced with your own identifying information. (Don't include
    183       the brackets!)  The text should be enclosed in the appropriate
    184       comment syntax for the file format. We also recommend that a
    185       file or class name and description of purpose be included on the
    186       same "printed page" as the copyright notice for easier
    187       identification within third-party archives.
    188 
    189    Copyright [2008] [Sebastian Przybylski, University of Siegen]
     1/*
     2   Copyright 2009 Holger Pretzsch, University of Duisburg-Essen
    1903
    1914   Licensed under the Apache License, Version 2.0 (the "License");
     
    21932using Cryptool.PluginBase.Miscellaneous;
    22033using System.Runtime.Remoting.Contexts;
     34using Cryptool.MD5.Presentation;
    22135
    22236namespace Cryptool.MD5
     
    22842    {
    22943        #region Private variables
     44
    23045        private MD5Settings settings;
    23146        private CryptoolStream inputData;
    23247        private byte[] outputData;
    23348        private List<CryptoolStream> listCryptoolStreamsOut = new List<CryptoolStream>();
     49        private PresentableMd5 md5;
     50        private PresentationContainer presentationContainer;
     51
    23452        #endregion
    23553
     
    23755        public MD5()
    23856        {
    239             this.settings = new MD5Settings();
     57            settings = new MD5Settings();
     58            md5 = new PresentableMd5();
     59            presentationContainer = new PresentationContainer(md5);
     60
     61            md5.StatusChanged += Md5StatusChanged;
    24062        }
    24163
     
    27496        public CryptoolStream OutputDataStream
    27597        {
    276          
    27798          get
    27899          {           
     
    287108            return null; ;
    288109          }
    289           set { } // readonly
    290110        }
    291111
     
    307127            }
    308128        }
     129
     130        void Md5StatusChanged()
     131        {
     132            if (md5.IsInFinishedState)
     133            {
     134                OutputData = md5.HashValueBytes;
     135                ProgressChanged(1.0, 1.0);
     136            }
     137        }
    309138       
    310139        public void Execute()
     
    313142          if (inputData != null)
    314143          {
    315             System.Security.Cryptography.MD5 md5Hash = System.Security.Cryptography.MD5.Create();
    316             byte[] data = md5Hash.ComputeHash((Stream)inputData);
    317 
    318             GuiLogMessage("Hash created.", NotificationLevel.Info);
    319             ProgressChanged(1, 1);           
    320             OutputData = data;           
     144              if (settings.PresentationMode)
     145              {
     146                  md5.Initialize(inputData);
     147              }
     148              else
     149              {
     150                  HashAlgorithm builtinMd5 = System.Security.Cryptography.MD5.Create();
     151                  OutputData = builtinMd5.ComputeHash(inputData);
     152                  ProgressChanged(1.0, 1.0);
     153              }
    321154          }
    322155          else
    323156          {           
    324               GuiLogMessage("Received null value for CryptoolStream.", NotificationLevel.Warning);           
    325           }
    326           ProgressChanged(1.0, 1.0);
     157              GuiLogMessage("Received null value for CryptoolStream.", NotificationLevel.Warning);
     158          }
    327159        }
    328160
     
    350182        public UserControl Presentation
    351183        {
    352           get { return null; }
     184          get { return presentationContainer; }
    353185        }
    354186
  • trunk/CrypPlugins/MD5/MD5.csproj

    r853 r863  
    4444      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4545    </Reference>
     46    <Reference Include="System.Drawing" />
     47    <Reference Include="System.Windows.Forms" />
    4648    <Reference Include="System.Xml.Linq">
    4749      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    5254    <Reference Include="System.Data" />
    5355    <Reference Include="System.Xml" />
     56    <Reference Include="UIAutomationProvider">
     57      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     58    </Reference>
    5459    <Reference Include="WindowsBase">
    5560      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     
    5762  </ItemGroup>
    5863  <ItemGroup>
     64    <Compile Include="Md5State.cs" />
    5965    <Compile Include="MD5.cs" />
    6066    <Compile Include="MD5Settings.cs" />
    6167    <Compile Include="PresentableMd5.cs" />
    6268    <Compile Include="PresentableMd5State.cs" />
     69    <Compile Include="Presentation\PresentationContainer.xaml.cs">
     70      <DependentUpon>PresentationContainer.xaml</DependentUpon>
     71    </Compile>
    6372    <Compile Include="Properties\AssemblyInfo.cs" />
    6473  </ItemGroup>
     
    8897  </ItemGroup>
    8998  <ItemGroup>
    90     <Folder Include="Presentation\" />
     99    <Page Include="Presentation\PresentationContainer.xaml">
     100      <SubType>Designer</SubType>
     101      <Generator>MSBuild:Compile</Generator>
     102    </Page>
    91103  </ItemGroup>
    92104  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  • trunk/CrypPlugins/MD5/MD5Settings.cs

    r136 r863  
    1 /*                              Apache License
    2                            Version 2.0, January 2004
    3                         http://www.apache.org/licenses/
    4 
    5    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    6 
    7    1. Definitions.
    8 
    9       "License" shall mean the terms and conditions for use, reproduction,
    10       and distribution as defined by Sections 1 through 9 of this document.
    11 
    12       "Licensor" shall mean the copyright owner or entity authorized by
    13       the copyright owner that is granting the License.
    14 
    15       "Legal Entity" shall mean the union of the acting entity and all
    16       other entities that control, are controlled by, or are under common
    17       control with that entity. For the purposes of this definition,
    18       "control" means (i) the power, direct or indirect, to cause the
    19       direction or management of such entity, whether by contract or
    20       otherwise, or (ii) ownership of fifty percent (50%) or more of the
    21       outstanding shares, or (iii) beneficial ownership of such entity.
    22 
    23       "You" (or "Your") shall mean an individual or Legal Entity
    24       exercising permissions granted by this License.
    25 
    26       "Source" form shall mean the preferred form for making modifications,
    27       including but not limited to software source code, documentation
    28       source, and configuration files.
    29 
    30       "Object" form shall mean any form resulting from mechanical
    31       transformation or translation of a Source form, including but
    32       not limited to compiled object code, generated documentation,
    33       and conversions to other media types.
    34 
    35       "Work" shall mean the work of authorship, whether in Source or
    36       Object form, made available under the License, as indicated by a
    37       copyright notice that is included in or attached to the work
    38       (an example is provided in the Appendix below).
    39 
    40       "Derivative Works" shall mean any work, whether in Source or Object
    41       form, that is based on (or derived from) the Work and for which the
    42       editorial revisions, annotations, elaborations, or other modifications
    43       represent, as a whole, an original work of authorship. For the purposes
    44       of this License, Derivative Works shall not include works that remain
    45       separable from, or merely link (or bind by name) to the interfaces of,
    46       the Work and Derivative Works thereof.
    47 
    48       "Contribution" shall mean any work of authorship, including
    49       the original version of the Work and any modifications or additions
    50       to that Work or Derivative Works thereof, that is intentionally
    51       submitted to Licensor for inclusion in the Work by the copyright owner
    52       or by an individual or Legal Entity authorized to submit on behalf of
    53       the copyright owner. For the purposes of this definition, "submitted"
    54       means any form of electronic, verbal, or written communication sent
    55       to the Licensor or its representatives, including but not limited to
    56       communication on electronic mailing lists, source code control systems,
    57       and issue tracking systems that are managed by, or on behalf of, the
    58       Licensor for the purpose of discussing and improving the Work, but
    59       excluding communication that is conspicuously marked or otherwise
    60       designated in writing by the copyright owner as "Not a Contribution."
    61 
    62       "Contributor" shall mean Licensor and any individual or Legal Entity
    63       on behalf of whom a Contribution has been received by Licensor and
    64       subsequently incorporated within the Work.
    65 
    66    2. Grant of Copyright License. Subject to the terms and conditions of
    67       this License, each Contributor hereby grants to You a perpetual,
    68       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    69       copyright license to reproduce, prepare Derivative Works of,
    70       publicly display, publicly perform, sublicense, and distribute the
    71       Work and such Derivative Works in Source or Object form.
    72 
    73    3. Grant of Patent License. Subject to the terms and conditions of
    74       this License, each Contributor hereby grants to You a perpetual,
    75       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    76       (except as stated in this section) patent license to make, have made,
    77       use, offer to sell, sell, import, and otherwise transfer the Work,
    78       where such license applies only to those patent claims licensable
    79       by such Contributor that are necessarily infringed by their
    80       Contribution(s) alone or by combination of their Contribution(s)
    81       with the Work to which such Contribution(s) was submitted. If You
    82       institute patent litigation against any entity (including a
    83       cross-claim or counterclaim in a lawsuit) alleging that the Work
    84       or a Contribution incorporated within the Work constitutes direct
    85       or contributory patent infringement, then any patent licenses
    86       granted to You under this License for that Work shall terminate
    87       as of the date such litigation is filed.
    88 
    89    4. Redistribution. You may reproduce and distribute copies of the
    90       Work or Derivative Works thereof in any medium, with or without
    91       modifications, and in Source or Object form, provided that You
    92       meet the following conditions:
    93 
    94       (a) You must give any other recipients of the Work or
    95           Derivative Works a copy of this License; and
    96 
    97       (b) You must cause any modified files to carry prominent notices
    98           stating that You changed the files; and
    99 
    100       (c) You must retain, in the Source form of any Derivative Works
    101           that You distribute, all copyright, patent, trademark, and
    102           attribution notices from the Source form of the Work,
    103           excluding those notices that do not pertain to any part of
    104           the Derivative Works; and
    105 
    106       (d) If the Work includes a "NOTICE" text file as part of its
    107           distribution, then any Derivative Works that You distribute must
    108           include a readable copy of the attribution notices contained
    109           within such NOTICE file, excluding those notices that do not
    110           pertain to any part of the Derivative Works, in at least one
    111           of the following places: within a NOTICE text file distributed
    112           as part of the Derivative Works; within the Source form or
    113           documentation, if provided along with the Derivative Works; or,
    114           within a display generated by the Derivative Works, if and
    115           wherever such third-party notices normally appear. The contents
    116           of the NOTICE file are for informational purposes only and
    117           do not modify the License. You may add Your own attribution
    118           notices within Derivative Works that You distribute, alongside
    119           or as an addendum to the NOTICE text from the Work, provided
    120           that such additional attribution notices cannot be construed
    121           as modifying the License.
    122 
    123       You may add Your own copyright statement to Your modifications and
    124       may provide additional or different license terms and conditions
    125       for use, reproduction, or distribution of Your modifications, or
    126       for any such Derivative Works as a whole, provided Your use,
    127       reproduction, and distribution of the Work otherwise complies with
    128       the conditions stated in this License.
    129 
    130    5. Submission of Contributions. Unless You explicitly state otherwise,
    131       any Contribution intentionally submitted for inclusion in the Work
    132       by You to the Licensor shall be under the terms and conditions of
    133       this License, without any additional terms or conditions.
    134       Notwithstanding the above, nothing herein shall supersede or modify
    135       the terms of any separate license agreement you may have executed
    136       with Licensor regarding such Contributions.
    137 
    138    6. Trademarks. This License does not grant permission to use the trade
    139       names, trademarks, service marks, or product names of the Licensor,
    140       except as required for reasonable and customary use in describing the
    141       origin of the Work and reproducing the content of the NOTICE file.
    142 
    143    7. Disclaimer of Warranty. Unless required by applicable law or
    144       agreed to in writing, Licensor provides the Work (and each
    145       Contributor provides its Contributions) on an "AS IS" BASIS,
    146       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    147       implied, including, without limitation, any warranties or conditions
    148       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
    149       PARTICULAR PURPOSE. You are solely responsible for determining the
    150       appropriateness of using or redistributing the Work and assume any
    151       risks associated with Your exercise of permissions under this License.
    152 
    153    8. Limitation of Liability. In no event and under no legal theory,
    154       whether in tort (including negligence), contract, or otherwise,
    155       unless required by applicable law (such as deliberate and grossly
    156       negligent acts) or agreed to in writing, shall any Contributor be
    157       liable to You for damages, including any direct, indirect, special,
    158       incidental, or consequential damages of any character arising as a
    159       result of this License or out of the use or inability to use the
    160       Work (including but not limited to damages for loss of goodwill,
    161       work stoppage, computer failure or malfunction, or any and all
    162       other commercial damages or losses), even if such Contributor
    163       has been advised of the possibility of such damages.
    164 
    165    9. Accepting Warranty or Additional Liability. While redistributing
    166       the Work or Derivative Works thereof, You may choose to offer,
    167       and charge a fee for, acceptance of support, warranty, indemnity,
    168       or other liability obligations and/or rights consistent with this
    169       License. However, in accepting such obligations, You may act only
    170       on Your own behalf and on Your sole responsibility, not on behalf
    171       of any other Contributor, and only if You agree to indemnify,
    172       defend, and hold each Contributor harmless for any liability
    173       incurred by, or claims asserted against, such Contributor by reason
    174       of your accepting any such warranty or additional liability.
    175 
    176    END OF TERMS AND CONDITIONS
    177 
    178    APPENDIX: How to apply the Apache License to your work.
    179 
    180       To apply the Apache License to your work, attach the following
    181       boilerplate notice, with the fields enclosed by brackets "[]"
    182       replaced with your own identifying information. (Don't include
    183       the brackets!)  The text should be enclosed in the appropriate
    184       comment syntax for the file format. We also recommend that a
    185       file or class name and description of purpose be included on the
    186       same "printed page" as the copyright notice for easier
    187       identification within third-party archives.
    188 
    189    Copyright [2008] [Sebastian Przybylski, University of Siegen]
     1/*
     2   Copyright 2009 Holger Pretzsch, University of Duisburg-Essen
    1903
    1914   Licensed under the Apache License, Version 2.0 (the "License");
     
    21427    {
    21528
    216       private bool hasChanges = false;
     29        private bool hasChanges = false;
    21730
    218       #region INotifyPropertyChanged Members
     31        #region INotifyPropertyChanged Members
    21932
    22033#pragma warning disable 67
    221                         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     34        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    22235#pragma warning restore
    223                        
    22436
    225       #endregion
    22637
    227       #region ISettings Members
     38        #endregion
    22839
    229       public bool HasChanges
    230       {
    231         get
     40
     41        private bool presentationMode = false;
     42        [TaskPane("Presentation mode", "With presentation mode enabled, results will not be generated ASAP. Instead, the generation steps can be individually traced from the Presentation screen.", null, 0, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     43        public bool PresentationMode
    23244        {
    233           return hasChanges;
     45            get { return presentationMode; }
     46            set
     47            {
     48                if (value != presentationMode)
     49                {
     50                    presentationMode = value;
     51                    hasChanges = true;
     52                    OnPropertyChanged("PresentationMode");
     53                }
     54            }
    23455        }
    235         set
     56
     57        private void OnPropertyChanged(string p)
    23658        {
    237           hasChanges = value;
     59            if (PropertyChanged != null)
     60                PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(p));
    23861        }
    239       }
    24062
    241       #endregion
     63        #region ISettings Members
     64
     65        public bool HasChanges
     66        {
     67            get
     68            {
     69                return hasChanges;
     70            }
     71            set
     72            {
     73                hasChanges = value;
     74            }
     75        }
     76
     77        #endregion
    24278    }
    24379}
  • trunk/CrypPlugins/MD5/PresentableMd5.cs

    r853 r863  
    55using System.Security.Cryptography;
    66using System.IO;
     7using System.ComponentModel;
    78
    89namespace Cryptool.MD5
    910{
    10     public class PresentableMd5
     11    public class PresentableMd5 : INotifyPropertyChanged
    1112    {
    1213        public List<PresentableMd5State> StateHistory { get; set; }
     
    5758        }
    5859
    59         public PresentableMd5(Stream dataStream)
    60         {
    61             Initialize(dataStream);
     60        public delegate void StatusChangedHandler();
     61        public event StatusChangedHandler StatusChanged;
     62
     63        public event PropertyChangedEventHandler PropertyChanged;
     64        void OnPropChanged(string propertyName)
     65        {
     66            if (PropertyChanged != null)
     67                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     68        }
     69
     70        private void OnStatusChanged()
     71        {
     72            OnPropChanged("CurrentState");
     73            OnPropChanged("LastState");
     74            OnPropChanged("CurrentStateNumber");
     75            OnPropChanged("IsInFinishedState");
     76
     77            if (StatusChanged != null)
     78                StatusChanged();
    6279        }
    6380
    6481        public PresentableMd5()
    6582        {
     83            StateHistory = new List<PresentableMd5State>();
     84            SetUninitializedState();
    6685        }
    6786
    6887        public void Initialize(Stream dataStream)
    6988        {
    70             StateHistory = new List<PresentableMd5State>();
    71 
    7289            DataStream = dataStream;
    7390
    74             InitFirstState();
     91            SetUninitializedState();
     92            PerformInitializationStep();
    7593
    7694            IsInitialized = true;
     95
     96            OnStatusChanged();
     97        }
     98
     99        private void SetUninitializedState()
     100        {
     101            StateHistory.Clear();
     102
     103            PresentableMd5State uninitializedState = new PresentableMd5State();
     104            uninitializedState.State = Md5State.UNINITIALIZED;
     105            StateHistory.Add(uninitializedState);
     106            CurrentState = uninitializedState;
     107
     108            CurrentStateNumber = 0;
    77109        }
    78110
     
    106138            CurrentStateNumber--;
    107139            CurrentState = StateHistory[CurrentStateNumber];
     140            OnStatusChanged();
    108141        }
    109142
     
    112145            get
    113146            {
    114                 return CurrentState.State == PresentableMd5State.Md5State.FINISHED;
     147                return CurrentState.State == Md5State.FINISHED;
     148            }
     149        }
     150
     151        public bool IsInFirstState
     152        {
     153            get
     154            {
     155                return CurrentStateNumber == 0;
    115156            }
    116157        }
     
    118159        public void NextStep()
    119160        {
     161            if (!IsInitialized)
     162                return;
     163
    120164            if (HistoryHasMoreStates)
    121165            {
    122166                CurrentStateNumber++;
    123167                CurrentState = StateHistory[CurrentStateNumber];
     168                OnStatusChanged();
    124169            }
    125170            else
     
    131176                AddNewState();
    132177                PerformStep(previousState, CurrentState);
     178                OnStatusChanged();
    133179            }
    134180        }
     
    136182        public void NextStepUntilFinished()
    137183        {
     184            if (!IsInitialized)
     185                return;
     186
    138187            while (!IsInFinishedState)
    139188                NextStep();
     
    142191        public void NextStepUntilRoundEnd()
    143192        {
    144             while (!IsInFinishedState && CurrentState.State != PresentableMd5State.Md5State.FINISHED_ROUND)
     193            if (!IsInitialized)
     194                return;
     195
     196            while (!IsInFinishedState && CurrentState.State != Md5State.FINISHED_ROUND)
    145197                NextStep();
    146198        }
     
    148200        public void NextStepUntilBlockEnd()
    149201        {
    150             while (!IsInFinishedState && CurrentState.State != PresentableMd5State.Md5State.FINISHED_COMPRESSION)
     202            if (!IsInitialized)
     203                return;
     204
     205            while (!IsInFinishedState && CurrentState.State != Md5State.FINISHED_COMPRESSION)
    151206                NextStep();
    152207        }
     
    156211            switch (previousState.State)
    157212            {
    158                 case PresentableMd5State.Md5State.INITIALIZED:
     213                case Md5State.INITIALIZED:
    159214                    // If initialization is complete, start by reading data
    160                     newState.State = PresentableMd5State.Md5State.READING_DATA;
    161                     break;
    162 
    163                 case PresentableMd5State.Md5State.READING_DATA:
     215                    newState.State = Md5State.READING_DATA;
     216                    break;
     217
     218                case Md5State.READING_DATA:
    164219                    // Read data and enter "data read" state
    165220                    ReadData(newState);
    166                     newState.State = PresentableMd5State.Md5State.READ_DATA;
    167                     break;
    168 
    169                 case PresentableMd5State.Md5State.READ_DATA:
     221                    newState.State = Md5State.READ_DATA;
     222                    break;
     223
     224                case Md5State.READ_DATA:
    170225                    // If an underfull buffer was read, we're at the end of the digestible data, so enter "starting padding" state
    171226                    // If a full buffer was read, enter "starting compression" state
    172227                    if (previousState.DataLength < DATA_BLOCK_SIZE)
    173                         newState.State = PresentableMd5State.Md5State.STARTING_PADDING;
     228                        newState.State = Md5State.STARTING_PADDING;
    174229                    else
    175                         newState.State = PresentableMd5State.Md5State.STARTING_COMPRESSION;
    176                     break;
    177 
    178                 case PresentableMd5State.Md5State.STARTING_PADDING:
     230                        newState.State = Md5State.STARTING_COMPRESSION;
     231                    break;
     232
     233                case Md5State.STARTING_PADDING:
    179234                    // First step of padding is adding the padding bytes, so enter that state
    180                     newState.State = PresentableMd5State.Md5State.ADDING_PADDING_BYTES;
    181                     break;
    182 
    183                 case PresentableMd5State.Md5State.ADDING_PADDING_BYTES:
     235                    newState.State = Md5State.ADDING_PADDING_BYTES;
     236                    break;
     237
     238                case Md5State.ADDING_PADDING_BYTES:
    184239                    // Add necessary number of bytes and enter "added padding bytes" state
    185240                    AddPaddingBytes(newState);
    186                     newState.State = PresentableMd5State.Md5State.ADDED_PADDING_BYTES;
    187                     break;
    188 
    189                 case PresentableMd5State.Md5State.ADDED_PADDING_BYTES:
     241                    newState.State = Md5State.ADDED_PADDING_BYTES;
     242                    break;
     243
     244                case Md5State.ADDED_PADDING_BYTES:
    190245                    // The next step for padding is adding the data length, so enter that state
    191                     newState.State = PresentableMd5State.Md5State.ADDING_LENGTH;
    192                     break;
    193 
    194                 case PresentableMd5State.Md5State.ADDING_LENGTH:
     246                    newState.State = Md5State.ADDING_LENGTH;
     247                    break;
     248
     249                case Md5State.ADDING_LENGTH:
    195250                    // Add the length of the data and enter "added length" state
    196251                    AddLength(newState);
    197                     newState.State = PresentableMd5State.Md5State.ADDED_LENGTH;
    198                     break;
    199 
    200                 case PresentableMd5State.Md5State.ADDED_LENGTH:
     252                    newState.State = Md5State.ADDED_LENGTH;
     253                    break;
     254
     255                case Md5State.ADDED_LENGTH:
    201256                    // Padding is done after adding data length, so enter "finished padding" state
    202                     newState.State = PresentableMd5State.Md5State.FINISHED_PADDING;
    203                     break;
    204 
    205                 case PresentableMd5State.Md5State.FINISHED_PADDING:
     257                    newState.State = Md5State.FINISHED_PADDING;
     258                    break;
     259
     260                case Md5State.FINISHED_PADDING:
    206261                    // If padding is finished, call compression function for the last (two) time(s)
    207                     newState.State = PresentableMd5State.Md5State.STARTING_COMPRESSION;
    208                     break;
    209 
    210                 case PresentableMd5State.Md5State.STARTING_COMPRESSION:
     262                    newState.State = Md5State.STARTING_COMPRESSION;
     263                    break;
     264
     265                case Md5State.STARTING_COMPRESSION:
    211266                    StartCompression(newState);
    212                     newState.State = PresentableMd5State.Md5State.STARTING_ROUND;
    213                     break;
    214 
    215                 case PresentableMd5State.Md5State.STARTING_ROUND:
     267                    newState.State = Md5State.STARTING_ROUND;
     268                    break;
     269
     270                case Md5State.STARTING_ROUND:
    216271                    StartRound(newState);
    217                     newState.State = PresentableMd5State.Md5State.STARTING_ROUND_STEP;
    218                     break;
    219 
    220                 case PresentableMd5State.Md5State.STARTING_ROUND_STEP:
     272                    newState.State = Md5State.STARTING_ROUND_STEP;
     273                    break;
     274
     275                case Md5State.STARTING_ROUND_STEP:
    221276                    PerformRoundStep(newState);
    222                     newState.State = PresentableMd5State.Md5State.FINISHED_ROUND_STEP;
    223                     break;
    224 
    225                 case PresentableMd5State.Md5State.FINISHED_ROUND_STEP:
     277                    newState.State = Md5State.FINISHED_ROUND_STEP;
     278                    break;
     279
     280                case Md5State.FINISHED_ROUND_STEP:
    226281                    if (previousState.IsLastStepInRound)
    227                         newState.State = PresentableMd5State.Md5State.FINISHED_ROUND;
     282                        newState.State = Md5State.FINISHED_ROUND;
    228283                    else
    229284                    {
    230                         newState._RoundStepIndex++;
    231                         newState.State = PresentableMd5State.Md5State.STARTING_ROUND_STEP;
     285                        newState.RoundStepIndex++;
     286                        newState.State = Md5State.STARTING_ROUND_STEP;
    232287                    }
    233288                    break;
    234289
    235                 case PresentableMd5State.Md5State.FINISHED_ROUND:
     290                case Md5State.FINISHED_ROUND:
    236291                    if (previousState.IsLastRound)
    237                         newState.State = PresentableMd5State.Md5State.FINISHING_COMPRESSION;
     292                        newState.State = Md5State.FINISHING_COMPRESSION;
    238293                    else
    239294                    {
    240                         newState._RoundIndex++;
    241                         newState.State = PresentableMd5State.Md5State.STARTING_ROUND;
     295                        newState.RoundIndex++;
     296                        newState.State = Md5State.STARTING_ROUND;
    242297                    }
    243298                    break;
    244299
    245                 case PresentableMd5State.Md5State.FINISHING_COMPRESSION:
     300                case Md5State.FINISHING_COMPRESSION:
    246301                    FinishCompression(newState);
    247                     newState.State = PresentableMd5State.Md5State.FINISHED_COMPRESSION;
    248                     break;
    249 
    250                 case PresentableMd5State.Md5State.FINISHED_COMPRESSION:
     302                    newState.State = Md5State.FINISHED_COMPRESSION;
     303                    break;
     304
     305                case Md5State.FINISHED_COMPRESSION:
    251306                    // If compression is finished, check if there's more data left in buffer. If so, reenter compression function with offset
    252307                    if (previousState.DataLength - previousState.DataOffset > DATA_BLOCK_SIZE)
     
    254309                        // Still some data left in buffer, rerun compression with offset
    255310                        newState.DataOffset += DATA_BLOCK_SIZE;
    256                         newState.State = PresentableMd5State.Md5State.STARTING_COMPRESSION;
     311                        newState.State = Md5State.STARTING_COMPRESSION;
    257312                    }
    258313                    else
     
    263318                        {
    264319                            // If padding was already added, we're done
    265                             newState.State = PresentableMd5State.Md5State.FINISHED;
     320                            newState.State = Md5State.FINISHED;
    266321                        }
    267322                        else
    268323                        {
    269324                            // Read more data
    270                             newState.State = PresentableMd5State.Md5State.READING_DATA;
     325                            newState.State = Md5State.READING_DATA;
    271326                        }
    272327                    }
     
    294349        private void StartRound(PresentableMd5State newState)
    295350        {
    296             newState._RoundStepIndex = 0;
     351            newState.RoundStepIndex = 0;
    297352        }
    298353
     
    309364            }
    310365
    311             newState._RoundIndex = 0;
     366            newState.RoundIndex = 0;
    312367
    313368            newState.A = newState.H1;
     
    343398        }
    344399
    345         public void InitFirstState()
    346         {
    347             Console.WriteLine("InitFirstState()");
    348 
    349             StateHistory.Clear();
    350             CurrentStateNumber = -1;
     400        public void PerformInitializationStep()
     401        {
    351402            AddNewState();
    352403
     
    356407            CurrentState.H3 = 0x98BADCFE;
    357408            CurrentState.H4 = 0X10325476;
    358             CurrentState.State = PresentableMd5State.Md5State.INITIALIZED;
     409            CurrentState.State = Md5State.INITIALIZED;
    359410        }
    360411
     
    371422            Console.WriteLine("Before R {0} S {1,2}: A = {2,10} B = {3,10} C = {4,10} D = {5,10}", newState.Round, newState.RoundStep, newState.A, newState.B, newState.C, newState.D);
    372423
    373             RoundFunction roundFunction = ROUND_FUNCTION[newState._RoundIndex];
    374 
    375             uint i = newState._RoundIndex * 16 + newState._RoundStepIndex;
     424            RoundFunction roundFunction = ROUND_FUNCTION[newState.RoundIndex];
     425
     426            uint i = newState.RoundIndex * 16 + newState.RoundStepIndex;
    376427
    377428            uint wordIndex;
    378             switch (newState._RoundIndex)
     429            switch (newState.RoundIndex)
    379430            {
    380431                default:
     
    394445            wordIndex %= 16;
    395446
    396             switch (newState._RoundStepIndex % 4)
    397             {
    398                 case 0:
    399                     ExecRoundFunction(ref newState.A, newState.B, newState.C, newState.D, roundFunction, newState.X[wordIndex], i);
    400                     break;
    401                 case 1:
    402                     ExecRoundFunction(ref newState.D, newState.A, newState.B, newState.C, roundFunction, newState.X[wordIndex], i);
    403                     break;
    404                 case 2:
    405                     ExecRoundFunction(ref newState.C, newState.D, newState.A, newState.B, roundFunction, newState.X[wordIndex], i);
    406                     break;
    407                 case 3:
    408                     ExecRoundFunction(ref newState.B, newState.C, newState.D, newState.A, roundFunction, newState.X[wordIndex], i);
    409                     break;
    410             }
     447            ExecRoundFunction(newState, roundFunction, newState.X[wordIndex], i);
    411448
    412449            if (newState.IsLastRound && newState.IsLastStepInRound)
     
    415452        }
    416453
    417         protected static void ExecRoundFunction(ref uint a, uint b, uint c, uint d, RoundFunction function, uint W, uint i)
    418         {
    419             a = b + RotateLeft((a + function(a, b, c, d) + W + AdditionConstantTable[i]), ShiftConstantTable[i]);
     454        protected static void ExecRoundFunction(PresentableMd5State state, RoundFunction function, uint W, uint i)
     455        {
     456            state.A = state.B + RotateLeft((state.A + function(state.A, state.B, state.C, state.D) + W + AdditionConstantTable[i]), ShiftConstantTable[i]);
     457
     458            uint oldD = state.D;
     459            state.D = state.C;
     460            state.C = state.B;
     461            state.B = state.A;
     462            state.A = oldD;
    420463        }
    421464
  • trunk/CrypPlugins/MD5/PresentableMd5State.cs

    r853 r863  
    44using System.Text;
    55using System.Reflection;
     6using System.Windows;
    67
    78namespace Cryptool.MD5
     
    910    public class PresentableMd5State
    1011    {
    11         internal enum Md5State
    12         {
    13             INITIALIZED,
    14             READING_DATA, READ_DATA,
    15             STARTING_PADDING, ADDING_PADDING_BYTES, ADDED_PADDING_BYTES, ADDING_LENGTH, ADDED_LENGTH, FINISHED_PADDING,
    16             STARTING_COMPRESSION, STARTING_ROUND, STARTING_ROUND_STEP, FINISHED_ROUND_STEP, FINISHED_ROUND, FINISHING_COMPRESSION, FINISHED_COMPRESSION,
    17             FINISHED
    18         }
     12        public Md5State State { get; set; }
    1913
    20         internal const int DATA_BLOCK_SIZE = 64;
     14        public const int DATA_BLOCK_SIZE = 64;
    2115
    22         internal uint A;
    23         internal uint B;
    24         internal uint C;
    25         internal uint D;
     16        public uint A { get; set; }
     17        public uint B { get; set; }
     18        public uint C { get; set; }
     19        public uint D { get; set; }
    2620
    27         internal uint _RoundIndex;
    28         internal uint Round
     21        public uint RoundIndex;
     22        public uint Round
    2923        {
    3024            get
    3125            {
    32                 return _RoundIndex + 1;
     26                return RoundIndex + 1;
    3327            }
    3428        }
    3529
    36         internal uint _RoundStepIndex;
    37         internal uint RoundStep
     30        public uint RoundStepIndex;
     31        public uint RoundStep
    3832        {
    3933            get
    4034            {
    41                 return _RoundStepIndex + 1;
     35                return RoundStepIndex + 1;
    4236            }
    4337        }
    4438
    45         internal uint BytesHashed;
     39        public uint BytesHashed { get; set; }
    4640
    47         internal bool IsPaddingDone;
     41        public bool IsPaddingDone { get; set; }
    4842
    49         internal bool IsLastStepInRound
     43        public bool IsLastStepInRound
    5044        {
    5145            get
     
    5549        }
    5650
    57         internal bool IsLastRound
     51        public bool IsLastRound
    5852        {
    5953            get
     
    6357        }
    6458
    65         internal uint H1;
    66         internal uint H2;
    67         internal uint H3;
    68         internal uint H4;
     59        public uint H1 { get; set; }
     60        public uint H2 { get; set; }
     61        public uint H3 { get; set; }
     62        public uint H4 { get; set; }
    6963
    70         internal uint[] X;
    71         internal byte[] Data;
    72         internal uint DataLength;
    73         internal uint DataOffset;
    74         internal ulong LengthInBit;
     64        public uint[] X { get; set; }
     65        public byte[] Data { get; set; }
     66        public uint DataLength { get; set; }
     67        public uint DataOffset { get; set; }
     68        public ulong LengthInBit { get; set; }
    7569
    76         internal Md5State State;
    77 
    78         internal PresentableMd5State()
     70        public PresentableMd5State()
    7971        {
    8072        }
    8173
    82         internal PresentableMd5State(PresentableMd5State other)
     74        public PresentableMd5State(PresentableMd5State other)
    8375        {
    8476            foreach (FieldInfo fi in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
    8577                fi.SetValue(this, fi.GetValue(other));
    86             H1 = other.H1;
     78
     79
     80            foreach (PropertyInfo pi in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
     81                if (pi.CanWrite && pi.CanRead)
     82                    pi.SetValue(this, pi.GetValue(other, null), null);
    8783        }
    8884    }
Note: See TracChangeset for help on using the changeset viewer.