Advertisement
defango

RSA Challenge

Dec 4th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. //Below is some code that will be useful later.
  2. //It is a BigInteger square root method and some strings related to and including RSA Challenge number 100. It is the smallest RSA //number, so it is good for examples.
  3. using System.Numerics;
  4. namespace IntegerFactorisation
  5. {
  6.     public static class Lib
  7.     {
  8.         public static string Rsa100c =
  9.             "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139";
  10.        
  11.         public static string Rsa100a = "37975227936943673922808872755445627854565536638199";
  12.         public static string Rsa100b = "40094690950920881030683735292761468389214899724061";
  13.         public static string Rsa100d = "39020571855401265512289573339484371018905006900194";
  14.         public static string Rsa100e = "61218444075812733697456051513875809617598014768503";
  15.         public static string Rsa100f = "16822699634989797327123095165092932420211999031886";//2d+1-e
  16.         public static string Rsa100n =     "14387588531011964456730684619177102985211280936";
  17.         public static string Rsa100x =   "1045343918457591589480700584038743164339470261995";
  18.         public static string Rsa100x_plus_n = "1059731506988603553937431268657920267324681542931";
  19.        
  20.         public static BigInteger Sqrt(this BigInteger number)
  21.         {
  22.             BigInteger n = 0, p = 0;
  23.             if (number == BigInteger.Zero)
  24.             {
  25.                 return BigInteger.Zero;
  26.             }
  27.             var high = number >> 1;
  28.             var low = BigInteger.Zero;
  29.             while (high > low + 1)
  30.             {
  31.                 n = (high + low) >> 1;
  32.                 p = n * n;
  33.                 if (number < p)
  34.                 {
  35.                     high = n;
  36.                 }
  37.                 else if (number > p)
  38.                 {
  39.                     low = n;
  40.                 }
  41.                 else
  42.                 {
  43.                     break;
  44.                 }
  45.             }
  46.             return number == p ? n : low;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement