Changeset 1632


Ignore:
Timestamp:
Jun 14, 2010, 10:57:56 AM (11 years ago)
Author:
Sven Rech
Message:

better id generation for quadratic sieve

Location:
trunk/CrypPlugins/QuadraticSieve
Files:
2 edited

Legend:

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

    r1630 r1632  
    2828using System.Windows.Threading;
    2929using System.Runtime.Serialization.Formatters.Binary;
     30using System.Management;
     31using System.Security.Principal;
     32using System.Security.Cryptography;
    3033
    3134namespace Cryptool.Plugins.QuadraticSieve
     
    7982        private void SetOurID()
    8083        {
    81             Random random = new Random();
    82             ourID = random.Next(1, Int32.MaxValue);        //TODO: Maybe we should calculate an id based on mac address and username?
     84            string username = WindowsIdentity.GetCurrent().Name;
     85            string mac = GetMac();
     86
     87            MD5 md5 = new MD5CryptoServiceProvider();
     88            byte[] idBytes = md5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(username + mac));           
     89           
     90            //Is it really a good idea to calculate the ID like this?
     91            for (int c = 0; c < idBytes.Length; c++)           
     92                ourID = ourID + (idBytes[c] << c);
     93
    8394            quadraticSieveQuickWatchPresentation.ProgressYields.setOurID(ourID);
     95
    8496            ourName = System.Net.Dns.GetHostName();
    8597        }
     
    394406        }
    395407
     408        public void StopLoadStoreThread()
     409        {
     410            stopLoadStoreThread = true;
     411            loadStoreThread.Interrupt();
     412            loadStoreThread.Join();
     413            loadStoreThread = null;
     414        }
     415
    396416        /// <summary>
    397417        /// Concatenates the two byte arrays a1 and a2 an returns the result array.
     
    404424            return res;
    405425        }
    406 
    407         public void StopLoadStoreThread()
    408         {
    409             stopLoadStoreThread = true;
    410             loadStoreThread.Interrupt();
    411             loadStoreThread.Join();
    412             loadStoreThread = null;
     426       
     427        /// <summary>
     428        /// Returns our MAC address
     429        /// </summary>       
     430        private string GetMac()
     431        {
     432            string Mac = string.Empty;
     433            ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
     434            ManagementObjectCollection MOCol = MC.GetInstances();
     435            foreach (ManagementObject MO in MOCol)
     436                if (MO != null)
     437                {
     438                    if (MO["MacAddress"] != null)
     439                    {
     440                        Mac = MO["MACAddress"].ToString();
     441                        if (Mac != string.Empty)
     442                            break;
     443                    }
     444                }
     445            return Mac;
    413446        }
    414447
     
    481514            else
    482515                head = 0;
    483 
    484             //SetOurID();
    485 
     516           
    486517            //store our name:
    487518            P2PManager.Retrieve(NameIdentifier(ourID));     //just to outsmart the versioning system
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSieve.csproj

    r1522 r1632  
    8585      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    8686    </Reference>
     87    <Reference Include="System.Management" />
    8788    <Reference Include="System.Numerics" />
    8889    <Reference Include="System.Xaml" />
Note: See TracChangeset for help on using the changeset viewer.