📄 multiprecision.java
字号:
package au.net.aba.pgp;
/*
* $Id: Multiprecision.java,v 1.2 1998/10/19 06:32:40 leachbj Exp $
* $Author: leachbj $
*
* Copyright (C) 1996-1998 Australian Business Access Pty Ltd.
* All rights reserved.
*
* Use, modification, copying and distribution of this software is subject the
* terms and conditions of the ABA Public Licence. See the file
* "PUBLIC_LICENCE" for additional information.
*
* If you have not received a copy of the Public Licence, you must destroy all
* copies of this file immediately.
*
* $Source: /aba/CVSROOT/jdk1.1/src/au.net.aba/pgp/Multiprecision.java,v $
* $Revision: 1.2 $
* $Date: 1998/10/19 06:32:40 $
* $State: Exp $
*/
import java.io.*;
import java.math.*;
/**
* A simple multiprecision integer class that manipulates large integers
* in a form compatible with the PGP representation.
*/
class Multiprecision
{
public final static String ident = "$Id: Multiprecision.java,v 1.2 1998/10/19 06:32:40 leachbj Exp $";
public int bits; // bits of precision (exact)
public byte[] octet; // bytes of value (octet[0] == LSB)
//
// Construct from an input stream.
//
public Multiprecision (InputStream input)
throws IOException
{
// read number of bits
DataInputStream data = new DataInputStream (input);
bits = data.readUnsignedShort ();
// non zero length?
if (bits > 0){
// read bytes of value
int length = (bits >> 3)
+ ((bits & 0x07) == 0 ? 0 : 1);
octet = new byte[length];
data.readFully (octet);
}
}
/**
* convert this to a BigInteger
*/
public BigInteger toBigInteger()
{
// we assume always non-zero
return new BigInteger(1, octet);
}
//
// Convert to a string.
//
public String toString ()
{
String s = "";
for (int i = 0; i < octet.length; i++){
if ((octet[i] & 0xff) < 16){
s += "0";
}
s += Integer.toString (octet[i] & 0xff,16);
}
return (s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -