Changeset 755


Ignore:
Timestamp:
Oct 20, 2009, 1:27:39 PM (12 years ago)
Author:
kopal
Message:
  • QuadraticSieve : added some comments to the code
Location:
trunk/CrypPlugins/QuadraticSieve
Files:
2 edited

Legend:

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

    r751 r755  
    3333namespace Cryptool.Plugins.QuadraticSieve
    3434{
     35    /// <summary>
     36    /// This class wraps the msieve algorithm in version 1.42 which you can find at http://www.boo.net/~jasonp/qs.html
     37    /// It also extends the msieve functionality to multi threading
     38    /// Many thanks to the author of msieve "jasonp_sf"
     39    ///
     40    /// For further information on quadratic sieve or msieve please have a look at the above mentioned URL
     41    /// </summary>
    3542    [Author("Sven Rech", "rech@cryptool.org", "Uni Duisburg-Essen", "http://www.uni-due.de")]
    3643    [PluginInfo(false, "Quadratic Sieve", "Sieving Primes", "", "QuadraticSieve/iconqs.png")]
    3744    class QuadraticSieve : DependencyObject, IThroughput
    3845    {
    39         #region IPlugin Members
     46        #region private variables
    4047
    4148        private const string TempDirectoryName = "CrypTool Temp Files";
     
    5663        private bool userStopped = false;
    5764
     65        #endregion
     66
     67        #region events
     68
     69        public event StatusChangedEventHandler OnPluginStatusChanged;
     70        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     71        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
     72        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     73        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
     74
     75        #endregion
     76
     77        /// <summary>
     78        /// Static constructor
     79        ///
     80        /// loads the msieve / msieve64 dll
     81        /// </summary>
    5882        static QuadraticSieve()
    5983        {
     
    7195            msieve = msieveDLL.GetType("Msieve.msieve");
    7296        }
    73 
     97       
     98        #region public
     99
     100        /// <summary>
     101        /// Constructor
     102        ///
     103        /// constructs a new QuadraticSieve plugin
     104        /// </summary>
    74105        public QuadraticSieve()
    75106        {
     
    85116        }               
    86117
    87         public event StatusChangedEventHandler OnPluginStatusChanged;
    88 
    89         public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    90 
    91         public event PluginProgressChangedEventHandler OnPluginProgressChanged;
    92 
     118        /// <summary>
     119        /// Getter / Setter for the settings of this plugin
     120        /// </summary>
    93121        public Cryptool.PluginBase.ISettings Settings
    94122        {
     
    97125        }           
    98126
     127        /// <summary>
     128        /// Called by the environment before executing this plugin
     129        /// </summary>
    99130        public void PreExecution()
    100131        { 
    101132        }
    102 
     133       
     134        /// <summary>
     135        /// Called by the environment to execute this plugin
     136        /// </summary>
    103137        public void Execute()
    104138        {
     
    198232            }
    199233        }
    200 
     234       
     235        /// <summary>
     236        /// Called by the environment after execution
     237        /// </summary>
     238        public void PostExecution()
     239        {
     240        }
     241
     242        /// <summary>
     243        /// Called by the environment to pause execution
     244        /// </summary>
     245        public void Pause()
     246        {
     247        }
     248
     249        /// <summary>
     250        /// Called by the environment to stop execution
     251        /// </summary>
     252        public void Stop()
     253        {
     254            this.userStopped = true;
     255            if (obj != IntPtr.Zero)
     256            {
     257                stopThreads();
     258                MethodInfo stop = msieve.GetMethod("stop");
     259                stop.Invoke(null, new object[] { obj });
     260            }
     261
     262        }
     263
     264        /// <summary>
     265        /// Called by the environment to initialize this plugin
     266        /// </summary>
     267        public void Initialize()
     268        {
     269        }
     270
     271        /// <summary>
     272        /// Called by the environment to dispose this plugin
     273        /// </summary>
     274        public void Dispose()
     275        {
     276        }
     277
     278        /// <summary>
     279        /// Getter / Setter for the input number which should be factorized
     280        /// </summary>
     281        [PropertyInfo(Direction.InputData, "Number input", "Enter the number you want to factorize", "", DisplayLevel.Beginner)]
     282        public BigInteger InputNumber
     283        {
     284            get
     285            {
     286                return inputNumber;
     287            }
     288            set
     289            {
     290                this.inputNumber = value;
     291                OnPropertyChanged("InputNumber");
     292            }
     293        }
     294
     295        /// <summary>
     296        /// Getter / Setter for the factors calculated by msieve
     297        /// </summary>
     298        [PropertyInfo(Direction.OutputData, "Factors output", "Your factors will be sent here", "", DisplayLevel.Beginner)]
     299        public BigInteger[] OutputFactors
     300        {
     301            get
     302            {
     303                return outputFactors;
     304            }
     305            set
     306            {
     307                this.outputFactors = value;
     308                OnPropertyChanged("OutputFactors");
     309            }
     310        }
     311       
     312        /// <summary>
     313        /// Called when a property of this plugin changes
     314        /// </summary>
     315        /// <param name="name">name</param>
     316        public void OnPropertyChanged(string name)
     317        {
     318            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
     319        }
     320
     321        /// <summary>
     322        /// Getter / Setter for the presentation of this plugin
     323        /// </summary>
     324        public UserControl Presentation { get; private set; }
     325
     326        /// <summary>
     327        /// Getter / Setter for the QuickWatchPresentation of this plugin
     328        /// </summary>
     329        public UserControl QuickWatchPresentation
     330        {
     331            get;
     332            private set;
     333        }
     334
     335        #endregion
     336
     337        #region private
     338
     339        /// <summary>
     340        /// calculate a String which shows the timespan
     341        ///
     342        /// example
     343        ///
     344        ///     4 days
     345        /// or
     346        ///     2 minutes
     347        /// </summary>
     348        /// <param name="ts"></param>
     349        /// <returns></returns>
    201350        private String showTimeSpan(TimeSpan ts)
    202351        {
     
    211360                res += ts.Seconds + " seconds";
    212361            return res;
    213         }
    214 
     362        }   
     363
     364        /// <summary>
     365        /// Actualize the progress
     366        /// </summary>
     367        /// <param name="conf"></param>
     368        /// <param name="num_relations"></param>
     369        /// <param name="max_relations"></param>
    215370        private void showProgress(IntPtr conf, int num_relations, int max_relations)
    216371        {
     
    264419        }
    265420
     421        /// <summary>
     422        /// Callback method to prepare sieving
     423        /// Called by msieve
     424        ///
     425        /// </summary>
     426        /// <param name="conf">pointer to configuration</param>
     427        /// <param name="update">number of relations found</param>
     428        /// <param name="core_sieve_fcn">pointer to internal sieve function of msieve</param>
    266429        private void prepareSieving (IntPtr conf, int update, IntPtr core_sieve_fcn)
    267430        {
     
    295458        }
    296459
    297         //Helper Thread for msieve, which sieves for relations:
     460        /// <summary>
     461        /// Helper Thread for msieve, which sieves for relations:
     462        /// </summary>
     463        /// <param name="param">params</param>
    298464        private void MSieveJob(object param)
    299465        {
     
    325491            freeSieveConf.Invoke(null, new object[] { clone });           
    326492            threadcount--;
    327         }
    328 
    329         public void PostExecution()
    330         {           
    331         }
    332 
    333         public void Pause()
    334         {           
    335         }
    336 
    337         public void Stop()
    338         {
    339             this.userStopped = true;
    340             if (obj != IntPtr.Zero)
    341             {
    342                 stopThreads();
    343                 MethodInfo stop = msieve.GetMethod("stop");
    344                 stop.Invoke(null, new object[] { obj });
    345             }
    346            
    347         }
    348 
     493        }       
     494
     495        /// <summary>
     496        /// Stop all running threads
     497        /// </summary>
    349498        private void stopThreads()
    350499        {
     
    355504                MethodInfo getObjFromConf = msieve.GetMethod("getObjFromConf");
    356505                foreach (IntPtr conf in conf_list)
    357                     stop.Invoke(null, new object[] { getObjFromConf.Invoke(null, new object[] {conf}) });
     506                    stop.Invoke(null, new object[] { getObjFromConf.Invoke(null, new object[] { conf }) });
    358507                GuiLogMessage("Waiting for threads to stop!", NotificationLevel.Debug);
    359508                while (threadcount > 0)
     
    364513                conf_list.Clear();
    365514            }
    366         }
    367 
    368         public void Initialize()
    369         {           
    370         }
    371 
    372         public void Dispose()
    373         {
     515        }   
     516
     517        /// <summary>
     518        /// Change the progress of this plugin
     519        /// </summary>
     520        /// <param name="value">value</param>
     521        /// <param name="max">max</param>
     522        private void ProgressChanged(double value, double max)
     523        {
     524            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
     525        }
     526
     527        /// <summary>
     528        /// Logs a message to the CrypTool gui
     529        /// </summary>
     530        /// <param name="p">p</param>
     531        /// <param name="notificationLevel">notificationLevel</param>
     532        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
     533        {
     534            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
     535        }
     536
     537        /// <summary>
     538        /// Getter / Setter for the QuickWatchPresentation
     539        /// </summary>
     540        private QuadraticSievePresentation quadraticSieveQuickWatchPresentation
     541        {
     542            get { return QuickWatchPresentation as QuadraticSievePresentation; }
    374543        }
    375544
    376545        #endregion
    377546
    378         #region QuadraticSieveInOut
    379 
    380         [PropertyInfo(Direction.InputData, "Number Input", "Put the number you want to factorize here", "", DisplayLevel.Beginner)]
    381         public BigInteger InputNumber
    382         {
    383             get
    384             {
    385                 return inputNumber;
    386             }
    387             set
    388             {
    389                 this.inputNumber = value;
    390                 OnPropertyChanged("InputNumber");
    391             }
    392         }
    393 
    394 
    395         [PropertyInfo(Direction.OutputData, "Factors Output", "Your factors will be sent here", "", DisplayLevel.Beginner)]
    396         public BigInteger[] OutputFactors
    397         {
    398             get
    399             {
    400                 return outputFactors;
    401             }
    402             set
    403             {
    404                 this.outputFactors = value;
    405                 OnPropertyChanged("OutputFactors");
    406             }
    407         }
    408 
    409         #endregion
    410 
    411         #region INotifyPropertyChanged Members
    412 
    413         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    414 
    415         public void OnPropertyChanged(string name)
    416         {
    417             EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
    418         }
    419 
    420         public event PluginProgressChangedEventHandler OnPluginProcessChanged;
    421 
    422         private void ProgressChanged(double value, double max)
    423         {
    424             EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
    425         }
    426 
    427         private void GuiLogMessage(string p, NotificationLevel notificationLevel)
    428         {
    429             EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
    430         }
    431 
    432         #endregion
    433 
    434         #region IPlugin Members
    435 
    436         private QuadraticSievePresentation quadraticSieveQuickWatchPresentation
    437         {
    438             get { return QuickWatchPresentation as QuadraticSievePresentation; }
    439         }
    440 
    441         public UserControl Presentation { get; private set; }
    442 
    443         public UserControl QuickWatchPresentation
    444         {
    445             get;
    446             private set;
    447         }
    448 
    449         #endregion
    450547    }
    451548}
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSieveSettings.cs

    r655 r755  
    3131        private int coresUsed;
    3232        private bool hasChanges = false;
     33        private ObservableCollection<string> coresAvailable = new ObservableCollection<string>();
     34        private bool deleteCache;
    3335        #endregion
    3436
     37        #region events
     38        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     39        #endregion
     40
     41        #region public
     42
     43        /// <summary>
     44        /// Constructs a new QuadraticSieveSettings
     45        ///
     46        /// Also calculates the amount of cores which can be used for the quadratic sieve
     47        /// </summary>
    3548        public QuadraticSieveSettings()
    3649        {
     
    4154        }
    4255
    43         #region taskpane
    44         [TaskPane("CoresUsed", "Choose how many cores should be used", null, 1, false, DisplayLevel.Beginner, ControlType.DynamicComboBox, new string[] { "CoresAvailable" })]
     56        /// <summary>
     57        /// Getter/Setter for the amount of cores which the user wants to have used by the quadratic sieve
     58        /// </summary>
     59        [TaskPane("CoresUsed", "Choose how many cores should be used for sieving", null, 1, false, DisplayLevel.Beginner, ControlType.DynamicComboBox, new string[] { "CoresAvailable" })]
    4560        public int CoresUsed
    4661        {
     
    5671            }
    5772        }
    58 
    59         private ObservableCollection<string> coresAvailable = new ObservableCollection<string>();
     73       
     74        /// <summary>
     75        /// Get the available amount of cores of this pc
     76        /// </summary>
    6077        public ObservableCollection<string> CoresAvailable
    6178        {
     
    7188        }
    7289
    73         private bool deleteCache;
    74         [TaskPane("Delete cache", "If checked, this plugin will delete the old cache file before it starts sieving.", null, 2, false, DisplayLevel.Expert, ControlType.CheckBox, "", null)]
     90        /// <summary>
     91        /// Getter / Setter to enable/disable the deletion of the cache
     92        /// </summary>
     93        [TaskPane("Delete cache", "If checked, this plugin will delete the old cache file before it starts sieving", null, 2, false, DisplayLevel.Expert, ControlType.CheckBox, "", null)]
    7594        public bool DeleteCache
    7695        {
     
    87106        }
    88107
    89         #endregion
    90 
    91         #region ISettings Members
    92 
     108        /// <summary>
     109        /// Called if the settings have changes
     110        /// </summary>
    93111        public bool HasChanges
    94112        {
     
    103121        }
    104122
    105        
    106 
    107123        #endregion
    108124
    109         #region INotifyPropertyChanged Members
     125        #region private
    110126
    111         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    112 
    113         private void OnPropertyChanged(string p)
     127        /// <summary>
     128        /// A property changed
     129        /// </summary>
     130        /// <param name="name">name</param>
     131        private void OnPropertyChanged(string name)
    114132        {
    115133            if (PropertyChanged != null)
    116134            {
    117                 PropertyChanged(this, new PropertyChangedEventArgs(p));
     135                PropertyChanged(this, new PropertyChangedEventArgs(name));
    118136            }
    119137        }
    120 
    121138
    122139        #endregion
Note: See TracChangeset for help on using the changeset viewer.