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

Last change on this file since 1705 was 1705, checked in by Paul Lelgemann, 12 years ago

o KeySearcher: improved visualization of local and distributed components

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