home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / security / util / BigInt.class (.txt) next >
Encoding:
Java Class File  |  1998-04-23  |  2.1 KB  |  108 lines

  1. package sun.security.util;
  2.  
  3. import java.math.BigInteger;
  4.  
  5. public final class BigInt {
  6.    private byte[] places;
  7.    private static final String digits = "0123456789abcdef";
  8.  
  9.    public BigInt(byte[] var1) {
  10.       this.places = var1;
  11.    }
  12.  
  13.    public BigInt(BigInteger var1) {
  14.       byte[] var2 = var1.toByteArray();
  15.       if ((var2[0] & 128) != 0) {
  16.          throw new IllegalArgumentException("negative BigInteger");
  17.       } else if (var2[0] != 0) {
  18.          this.places = var2;
  19.       } else {
  20.          this.places = new byte[var2.length - 1];
  21.  
  22.          for(int var3 = 1; var3 < var2.length; ++var3) {
  23.             this.places[var3 - 1] = var2[var3];
  24.          }
  25.  
  26.       }
  27.    }
  28.  
  29.    public BigInt(int var1) {
  30.       if (var1 < 256) {
  31.          this.places = new byte[1];
  32.          this.places[0] = (byte)var1;
  33.       } else if (var1 < 65536) {
  34.          this.places = new byte[2];
  35.          this.places[0] = (byte)var1;
  36.          this.places[1] = (byte)(var1 >> 8);
  37.       } else if (var1 < 16777216) {
  38.          this.places = new byte[3];
  39.          this.places[0] = (byte)var1;
  40.          this.places[1] = (byte)(var1 >> 8);
  41.          this.places[2] = (byte)(var1 >> 16);
  42.       } else {
  43.          this.places = new byte[4];
  44.          this.places[0] = (byte)var1;
  45.          this.places[1] = (byte)(var1 >> 8);
  46.          this.places[2] = (byte)(var1 >> 16);
  47.          this.places[3] = (byte)(var1 >> 24);
  48.       }
  49.    }
  50.  
  51.    public int toInt() {
  52.       if (this.places.length > 4) {
  53.          throw new NumberFormatException("BigInt.toLong, too big");
  54.       } else {
  55.          int var1 = 0;
  56.  
  57.          int var2;
  58.          for(var2 = 0; var1 < this.places.length; ++var1) {
  59.             var2 <<= 8;
  60.             var2 += 255 & this.places[var1];
  61.          }
  62.  
  63.          return var2;
  64.       }
  65.    }
  66.  
  67.    public String toString() {
  68.       return this.hexify();
  69.    }
  70.  
  71.    public BigInteger toBigInteger() {
  72.       return new BigInteger(1, this.places);
  73.    }
  74.  
  75.    public byte[] toByteArray() {
  76.       return this.places;
  77.    }
  78.  
  79.    private String hexify() {
  80.       StringBuffer var1 = new StringBuffer(this.places.length * 2);
  81.       var1.append("    ");
  82.  
  83.       for(int var2 = 0; var2 < this.places.length; ++var2) {
  84.          var1.append("0123456789abcdef".charAt(this.places[var2] >> 4 & 15));
  85.          var1.append("0123456789abcdef".charAt(this.places[var2] & 15));
  86.          if ((var2 + 1) % 32 == 0) {
  87.             if (var2 + 1 != this.places.length) {
  88.                var1.append("\n    ");
  89.             }
  90.          } else if ((var2 + 1) % 4 == 0) {
  91.             var1.append(' ');
  92.          }
  93.       }
  94.  
  95.       return var1.toString();
  96.    }
  97.  
  98.    public boolean equals(Object var1) {
  99.       return var1 instanceof BigInt ? this.equals((BigInt)var1) : false;
  100.    }
  101.  
  102.    public boolean equals(BigInt var1) {
  103.       BigInteger var2 = new BigInteger(1, this.toByteArray());
  104.       BigInteger var3 = new BigInteger(1, var1.toByteArray());
  105.       return var2.equals(var3);
  106.    }
  107. }
  108.