Ignore:
Timestamp:
Jan 19, 2010, 1:09:59 PM (12 years ago)
Author:
arnold
Message:

Fixed Ticket #131 - but in AES and SDES the new Decrypt-Method isn't implemented yet. Do be done by the specific Engineers.
Also fixed the other KeySearcher-Samples (DES, SDES and AES).
Still a bug: After reloading the Sample all In- and Outputs are visible event though the second Encryption-PlugIn is slave-connected

File:
1 edited

Legend:

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

    r1083 r1089  
    6363                {
    6464                    controlMaster.keyPatternChanged -= keyPatternChanged;
    65                     controlMaster.OnStatusChanged -= onStatusChanged;
    6665                }
    6766                if (value != null)
     
    6968                    Pattern = new KeyPattern(value.getKeyPattern());
    7069                    value.keyPatternChanged += keyPatternChanged;
    71                     value.OnStatusChanged += onStatusChanged;
    7270                    controlMaster = value;
    7371                    OnPropertyChanged("ControlMaster");
     
    9795
    9896        /* BEGIN: following lines are from Arnie - 2010.01.12 */
    99         CryptoolStream decryptedData;
    100         [PropertyInfo(Direction.InputData,"Encrypted Data","Encrypted data out of an Encryption PlugIn","",true,false,DisplayLevel.Beginner,QuickWatchFormat.Hex,"")]
    101         public CryptoolStream DecryptedData
    102         {
    103             get { return this.decryptedData; }
     97        CryptoolStream csEncryptedData;
     98        [PropertyInfo(Direction.InputData, "CS Encrypted Data", "Encrypted data out of an Encryption PlugIn", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, "")]
     99        public virtual CryptoolStream CSEncryptedData
     100        {
     101            get { return this.csEncryptedData; }
    104102            set
    105103            {
    106                 if (value != this.decryptedData)
    107                 {
    108                     this.decryptedData = value;
     104                if (value != this.csEncryptedData)
     105                {
     106                    this.csEncryptedData = value;
     107                    cryptoolStreamChanged = true;
     108                    OnPropertyChanged("CSEncryptedData");
     109                }
     110            }
     111        }
     112
     113        byte[] encryptedData;
     114        [PropertyInfo(Direction.InputData,"Encrypted Data","Encrypted data out of an Encryption PlugIn","",false,false,DisplayLevel.Beginner,QuickWatchFormat.Hex,"")]
     115        public virtual byte[] EncryptedData
     116        {
     117            get { return this.encryptedData; }
     118            set
     119            {
     120                if (value != this.encryptedData)
     121                {
     122                    this.encryptedData = value;
    109123                    cryptoolStreamChanged = true;
    110124                    OnPropertyChanged("EncryptedData");
     
    117131        /// </summary>
    118132        private bool cryptoolStreamChanged = false;
    119         private byte[] decryptedByteData;
     133        private byte[] encryptedByteData;
    120134        private byte[] GetByteFromCryptoolStream(CryptoolStream cryptoolStream)
    121135        {
    122136            // only transform CryptoolStream to Byte[], if there is a new CryptoolStream
    123137            // or decryptedByteData is Null
    124             if (cryptoolStreamChanged || decryptedByteData == null)
     138            if (cryptoolStreamChanged || encryptedByteData == null)
    125139            {
    126140                CryptoolStream cs = new CryptoolStream();
    127141                cs.OpenRead(cryptoolStream.FileName);
    128                 decryptedByteData = new byte[cs.Length];
     142                encryptedByteData = new byte[cs.Length];
    129143                if(cs.Length > Int32.MaxValue)
    130144                    throw(new Exception("CryptoolStream length is longer than the Int32.MaxValue"));
    131                 cs.Read(decryptedByteData, 0, (int)cs.Length);
    132             }
    133             return decryptedByteData;
     145                cs.Read(encryptedByteData, 0, (int)cs.Length);
     146            }
     147            return encryptedByteData;
    134148        }
    135149
    136150        byte[] initVector;
    137151        [PropertyInfo(Direction.InputData, "Initialization Vector", "Initialization vector with which the data were encrypted", "", DisplayLevel.Beginner)]
    138         public byte[] InitVector
     152        public virtual byte[] InitVector
    139153        {
    140154            get { return this.initVector; }
     
    190204
    191205        // because Encryption PlugIns were changed radical, the new StartPoint is here - Arnie 2010.01.12
    192         public void Execute()
    193         {
    194             if (this.DecryptedData != null) //to prevent execution on initialization
     206        public virtual void Execute()
     207        {
     208            //either byte[] CStream input or CryptoolStream Object input
     209            if (this.EncryptedData != null || this.CSEncryptedData != null) //to prevent execution on initialization
    195210            {
    196211                if (this.ControlMaster != null)
     
    414429            try
    415430            {
    416                 byte[] decryptedData = GetByteFromCryptoolStream(this.DecryptedData);
    417                 valueKey.decryption = sender.Decrypt(decryptedData, keya);
     431                CryptoolStream cs = new CryptoolStream();
     432                if (this.CSEncryptedData == null)
     433                {
     434                    cs.OpenRead(this.EncryptedData);
     435                    valueKey.decryption = sender.Decrypt(this.EncryptedData, keya);
     436                }
     437                else
     438                {
     439                    cs.OpenRead(this.CSEncryptedData.FileName);
     440                    byte[] byteCS = new byte[cs.Length];
     441                    cs.Read(byteCS, 0, byteCS.Length);
     442                    //this.CSEncryptedData.Read(byteCS, 0, byteCS.Length);
     443                    valueKey.decryption = sender.Decrypt(byteCS, keya);
     444                }
     445
    418446                //valueKey.decryption = sender.Decrypt(keya, bytesToUse);
    419447            }
     
    744772                doneKeysA[i] = new BigInteger();
    745773                keycounters[i] = new BigInteger();
    746                 ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, keycounters, keysleft, sender.clone(), bytesToUse, threadStack });
     774                //ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, keycounters, keysleft, sender.clone(), bytesToUse, threadStack });
     775                ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, keycounters, keysleft, sender, bytesToUse, threadStack });
    747776            }
    748777        }
     
    783812            Pattern = new KeyPattern(controlMaster.getKeyPattern());
    784813        }
    785 
    786         // set to protected by Christian Arnold - 2009.12.06
    787         protected virtual void onStatusChanged(IControl sender, bool readyForExecution)
    788         {
    789             // doesn't work anymore, because Encryption PlugIns were changed radical!!! Arnie 2010.01.12
    790             if (readyForExecution)
    791             {
    792                 this.process((IControlEncryption)sender);
    793             }
    794         }
    795 
    796814
    797815        // added by Arnie - 2009.12.07
     
    805823        // added by Arnie -2009.12.02
    806824        // for inheritance reasons
    807         public void BruteforcePattern(KeyPattern pattern, IControlEncryption encryptControl, IControlCost costControl)
    808         {
    809             //ControlMaster = encryptControl;
    810             //CostMaster = costControl;
     825        public void BruteforcePattern(KeyPattern pattern, byte[] encryptedData, byte[] initVector, IControlEncryption encryptControl, IControlCost costControl)
     826        {
     827            /* Begin: New stuff because of changing the IControl data flow - Arnie 2010.01.18 */
     828            this.EncryptedData = encryptedData;
     829            this.InitVector = initVector;
     830            /* End: New stuff because of changing the IControl data flow - Arnie 2010.01.18 */
     831           
    811832            LinkedList<ValueKey> lstRet = bruteforcePattern(pattern, encryptControl);
    812833            if(OnBruteforcingEnded != null)
Note: See TracChangeset for help on using the changeset viewer.