source: trunk/CrypPlugins/KeySearcher/Presentation/Controls/P2PQuickWatchPresentation.xaml.cs @ 2189

Last change on this file since 2189 was 2189, checked in by matkovic, 11 years ago

-added numeric separators

File size: 2.6 KB
Line 
1using System;
2using System.Numerics;
3using System.Windows;
4using System.Windows.Controls;
5using KeySearcher;
6using KeySearcher.KeyPattern;
7using System.Globalization;
8
9namespace KeySearcherPresentation.Controls
10{
11    public partial class P2PQuickWatchPresentation : UserControl
12    {
13        public static readonly DependencyProperty IsVerboseEnabledProperty = DependencyProperty.Register("IsVerboseEnabled", typeof(Boolean), typeof(P2PQuickWatchPresentation), new PropertyMetadata(false));
14        public Boolean IsVerboseEnabled
15        {
16            get { return (Boolean)GetValue(IsVerboseEnabledProperty); }
17            set { SetValue(IsVerboseEnabledProperty, value); }
18        }
19
20        public NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
21
22        public P2PQuickWatchPresentation()
23        {
24            InitializeComponent();
25        }
26
27        public static readonly DependencyProperty IsOpenCLEnabledProperty =
28            DependencyProperty.Register("IsOpenCLEnabled",
29                        typeof(Boolean),
30                        typeof(P2PQuickWatchPresentation), new PropertyMetadata(false));
31
32        public Boolean IsOpenCLEnabled
33        {
34            get { return (Boolean)GetValue(IsOpenCLEnabledProperty); }
35            set { SetValue(IsOpenCLEnabledProperty, value); }
36        }
37
38        public void UpdateSettings(KeySearcher.KeySearcher keySearcher, KeySearcherSettings keySearcherSettings)
39        {
40            IsVerboseEnabled = keySearcherSettings.VerbosePeerToPeerDisplay;
41
42            if (keySearcher.Pattern == null || !keySearcher.Pattern.testWildcardKey(keySearcherSettings.Key) || keySearcherSettings.ChunkSize == 0)
43            {
44                return;
45            }
46
47            var keyPattern = new KeyPattern(keySearcher.ControlMaster.getKeyPattern())
48                                 {WildcardKey = keySearcherSettings.Key};
49            var keysPerChunk = Math.Pow(2, keySearcherSettings.ChunkSize);
50            var keyPatternPool = new KeyPatternPool(keyPattern, new BigInteger(keysPerChunk));
51
52            if (keyPatternPool.Length > 9999999999)
53            {
54                TotalAmountOfChunks.Content = keyPatternPool.Length.ToString().Substring(0, 10) + "...";
55            }
56            else
57            {
58                TotalAmountOfChunks.Content = keyPatternPool.Length;
59            }
60
61            KeysPerChunk.Content = keysPerChunk;
62            TestedBits.Content = Math.Ceiling(Math.Log((double) keyPatternPool.Length*keysPerChunk, 2));
63        }
64    }
65}
Note: See TracBrowser for help on using the repository browser.