/// <summary> /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class. /// </summary> /// <param name="codeLength">Length of the code.</param> /// <param name="rsaPublicKey">The RSA public key.</param> /// <param name="initialAlphabet">The initial alphabet.</param> /// <param name="finalAlphabet">The final alphabet.</param> public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, string initialAlphabet, string finalAlphabet) : this( codeLength, rsaPublicKey, new AsciiStringTranslator(initialAlphabet, finalAlphabet, true)) { }
/// <summary> /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class. /// </summary> /// <param name="codeLength">Length of the code.</param> /// <param name="rsaPublicKey">The RSA public key.</param> /// <param name="translator">The translator.</param> public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, IStringTranslator translator) { if (codeLength < 1) { throw new ArgumentOutOfRangeException("codeLength", "codeLenth must be greater than zero."); } if (rsaPublicKey == null) { throw new ArgumentNullException("rsaPublicKey"); } if (translator == null) { throw new ArgumentNullException("translator"); } char[] alphabetLetters = translator.FinalAlphabet.ToCharArray(); Array.Sort(alphabetLetters); int i = 0; foreach (char alphabetLetter in alphabetLetters) { // Ignore duplicates if (alphabetLetter != correctDigitSequence[i]) { // Not a duplicate, move to next char in valid sequence of digits i++; if (alphabetLetter != correctDigitSequence[i]) { throw new ArgumentException("The final alphabet does not contain a valid digit sequence.", "translator"); } } } radix = i + 1; rsa = new RsaSmall(new RsaSmallFullKey(rsaPublicKey.Modulus, 0, rsaPublicKey.Exponent)); this.translator = translator; validCodeRegex = string.Format(CultureInfo.InvariantCulture, @"^[{0}]{{{1}}}$", translator.InitialAlphabet, codeLength); }
/// <summary> /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class. /// </summary> /// <param name="codeLength">Length of the code.</param> /// <param name="rsaPublicKey">The RSA public key.</param> /// <param name="translator">The translator.</param> public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, IStringTranslator translator) { if(codeLength < 1) { throw new ArgumentOutOfRangeException("codeLength", "codeLenth must be greater than zero."); } if (rsaPublicKey == null) { throw new ArgumentNullException("rsaPublicKey"); } if (translator == null) { throw new ArgumentNullException("translator"); } char[] alphabetLetters = translator.FinalAlphabet.ToCharArray(); Array.Sort(alphabetLetters); int i = 0; foreach (char alphabetLetter in alphabetLetters) { // Ignore duplicates if (alphabetLetter != correctDigitSequence[i]) { // Not a duplicate, move to next char in valid sequence of digits i++; if (alphabetLetter != correctDigitSequence[i]) { throw new ArgumentException("The final alphabet does not contain a valid digit sequence.", "translator"); } } } radix = i + 1; rsa = new RsaSmall(new RsaSmallFullKey(rsaPublicKey.Modulus, 0, rsaPublicKey.Exponent)); this.translator = translator; validCodeRegex = string.Format(CultureInfo.InvariantCulture, @"^[{0}]{{{1}}}$", translator.InitialAlphabet, codeLength); }
/// <summary> /// Initializes a new instance of the <see cref="RsaSmallFullKey"/> class. /// </summary> /// <param name="modulus">The modulus.</param> /// <param name="privateExponent">The private exponent.</param> /// <param name="publicExponent">The public exponent.</param> public RsaSmallFullKey(BigInteger modulus, BigInteger privateExponent, BigInteger publicExponent) { privateKey = new RsaSmallPrivateKey(modulus, privateExponent); publicKey = new RsaSmallPublicKey(modulus, publicExponent); }
/// <summary> /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class. /// </summary> /// <param name="codeLength">Length of the code.</param> /// <param name="rsaPublicKey">The RSA public key.</param> /// <param name="initialAlphabet">The initial alphabet.</param> /// <param name="finalAlphabet">The final alphabet.</param> public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, string initialAlphabet, string finalAlphabet) : this(codeLength, rsaPublicKey, new AsciiStringTranslator(initialAlphabet, finalAlphabet, true)) { }