Ignore:
Timestamp:
May 20, 2010, 12:35:16 PM (12 years ago)
Author:
Sven Rech
Message:

replaced all BigInteger stuff with the new BigInteger class from .net 4.0

But there are still problems with some plugins (Keysearcher, BigInteger Operations...)

File:
1 edited

Legend:

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

    r1029 r1448  
    2626using System.Threading;
    2727using System.Collections;
     28using System.Numerics;
    2829
    2930namespace Cryptool.Plugins.RSA
     
    117118            //calculate the BigIntegers
    118119            try{
    119                 if (this.InputN is object && this.InputED is object && this.InputMC is object && !stopped)   
    120                     this.OutputMC = InputMC.modPow(this.InputED, this.InputN);
     120                if (this.InputN != 0 && this.InputED != 0 && this.InputMC != 0 && !stopped)
     121                    this.OutputMC = BigInteger.ModPow(InputMC, this.InputED, this.InputN);
    121122            }
    122123            catch (Exception ex)
     
    128129            // RSA on Texts
    129130            //
    130             if (this.InputText is object && this.InputN is object && this.InputED is object && !stopped)
     131            if (this.InputText is object && this.InputN != 0 && this.InputED != 0 && !stopped)
    131132            {
    132133                DateTime startTime = DateTime.Now;
     
    141142                if (settings.Action == 0)
    142143                {
    143                     blocksize_input = (int)Math.Floor(this.InputN.log(256));
    144                     blocksize_output = (int)Math.Ceiling(this.InputN.log(256));
     144                    blocksize_input = (int)Math.Floor(BigInteger.Log(InputN, 256));
     145                    blocksize_output = (int)Math.Ceiling(BigInteger.Log(InputN, 256));
    145146                }
    146147                //Decryption
    147148                else
    148149                {
    149                     blocksize_input = (int)Math.Ceiling(this.InputN.log(256));
    150                     blocksize_output = (int)Math.Floor(this.InputN.log(256));
     150                    blocksize_input = (int)Math.Ceiling(BigInteger.Log(InputN, 256));
     151                    blocksize_output = (int)Math.Floor(BigInteger.Log(InputN, 256));
    151152                }
    152153
     
    387388
    388389                    //create a big integer from a block
    389                     byte[] help = new byte[blocksize_input];
     390                    byte[] help = new byte[blocksize_input+1];
    390391                    for (int j = 0; j < blocksize_input; j++)
    391392                    {
     
    394395                        if (stopped)
    395396                            return;
    396 
    397397                    }
    398398                    bint = new BigInteger(help);
     
    408408
    409409                    //here we encrypt/decrypt with rsa algorithm
    410                     bint = bint.modPow(this.InputED, this.InputN);
     410                    bint = BigInteger.ModPow(bint, this.InputED, this.InputN);
    411411
    412412                    //create a block from the byte array of the BigInteger
    413                     byte[] bytes = bint.getBytes();
     413                    byte[] bytes = removeZeros(bint.ToByteArray());
    414414                    int diff = (blocksize_output - (bytes.Length % blocksize_output)) % blocksize_output;
    415415
    416416                    for (int j = 0; j < bytes.Length; j++)
    417417                    {
    418                         output[i * blocksize_output + j + diff] = bytes[j];
     418                        output[i * blocksize_output + j/* + diff*/] = bytes[j];
    419419                        if (stopped)
    420420                            return;
Note: See TracChangeset for help on using the changeset viewer.