Advertisement
Guest User

vqc.java v0.1

a guest
Mar 1st, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.math.BigInteger;
  3.  
  4. public class vqc{
  5.  
  6. private static final BigInteger minusOne = BigInteger.valueOf(-1);
  7. private static final BigInteger zero = BigInteger.valueOf(0);
  8. private static final BigInteger one = BigInteger.valueOf(1);
  9. private static final BigInteger two = BigInteger.valueOf(2);
  10. private static final BigInteger four = BigInteger.valueOf(4);
  11.  
  12. public static void main(String[] args){
  13. Scanner scan = new Scanner(System.in);
  14. System.out.println("c=");
  15. BigInteger c = zero;
  16. try{
  17. c = new BigInteger(scan.nextLine());
  18. } catch(Exception e){
  19. System.err.println("c is supposed to be a number");
  20. return;
  21. }
  22. while((c.mod(four)).equals(two)){
  23. c = c.divide(two);
  24. }
  25. BigInteger d = sqrt(c);
  26. BigInteger e = c.subtract(d.multiply(d));
  27. BigInteger n = factor(d, e);
  28. }
  29.  
  30. public static BigInteger factor(BigInteger d, BigInteger e){
  31. BigInteger c = (d.multiply(d)).add(e);
  32. BigInteger cBigNx = c.subtract(d);
  33. BigInteger cBigNt = zero;
  34. if((e.mod(two)).equals(zero)){
  35. cBigNt = (cBigNx.add(two)).divide(two);
  36. } else {
  37. cBigNt = (cBigNx.add(one)).divide(two);
  38. }
  39.  
  40. Element aLow = e1Element(e, zero); //t=0
  41. Element aHigh = e1Element(e, cBigNt); //a[t]=c*BigN
  42. /*
  43. while(!((aLow.a()).equals(aHigh.a()))){
  44. if(isOddType1(c)){
  45. //something
  46. } else if(isOddType2(c)){
  47. //something
  48. } else if(isOddType3(c)){
  49. //something
  50. } else if(isOddType4(c)){
  51. //something
  52. }
  53. }
  54. */
  55. return zero;
  56. }
  57.  
  58. public static BigInteger sqrt(BigInteger x) {
  59. if(x.compareTo(zero) == -1){
  60. x = x.multiply(minusOne);
  61. }
  62. if(x.equals(zero)){
  63. return zero;
  64. }
  65. BigInteger div = zero.setBit(x.bitLength()/2);
  66. BigInteger div2 = div;
  67. BigInteger returnvalue = zero;
  68. for(;;) {
  69. BigInteger y = div.add(x.divide(div)).shiftRight(1);
  70. if (y.equals(div) || y.equals(div2)){
  71. returnvalue = y;
  72. break;
  73. }
  74. div2 = div;
  75. div = y;
  76. }
  77.  
  78. BigInteger testsquare = returnvalue.multiply(returnvalue);
  79. BigInteger testp1square = (returnvalue.add(one)).multiply(returnvalue.add(one));
  80. if((testsquare.equals(x)) || (((testsquare.compareTo(x)) == -1) && ((testp1square.compareTo(x)) == 1))){
  81. return returnvalue;
  82. } else {
  83. return returnvalue.subtract(one);
  84. }
  85. }
  86.  
  87. public static Element e1Element(BigInteger e, BigInteger t){
  88. BigInteger x = zero;
  89. if((e.mod(two)).equals(zero)){
  90. x = (t.subtract(one)).multiply(two);
  91. } else {
  92. x = (t.multiply(two)).subtract(one);
  93. }
  94.  
  95. BigInteger xx = x.multiply(x);
  96. BigInteger xxpe = xx.add(e);
  97. BigInteger a = ((x.multiply(x)).add(e)).divide(two);
  98. BigInteger b = a.add(x.multiply(two)).add(two);
  99.  
  100. if(e.compareTo(zero) == -1){
  101. return new Element(a, b, e); //(f,1)
  102. } else {
  103. return new Element(a, b); //(e,1)
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement