Cryptography Reference
In-Depth Information
CHAPTER 2
Large Integer Computing
The vast majority of modern cryptography is handled by computers, which deal very
efficiently with numbers, especially integers. Thus, not surprisingly, we find that much
of modern cryptography is based on arithmetic with large integers. Of course, the default
integer data type for computing languages is limited in size, so programmers are often faced
with producing a new data type for integers of arbitrary size. Java, however, does provide
a BigInteger class, and it is very useful in cryptography. We will discuss this class later in
the topic, but first it would be enlightening to try to produce a similar class of our own.
So, we begin developing an Int class. It can be supplied with various methods that manip-
ulate integers of arbitrary size; that is, it should be able to perform arithmetic with integers
of hundreds or even thousands of decimal digits. Such integers are common in modern cryp-
tography.
The Int class data fields should be able to represent an integer of arbitrary size in some
way, and also be able to represent some constructors that accept parameters to initialize the
data fields. We could represent the integer as an array of ints, where each int is a digit. (See
Figure 2.1.) We could also have a boolean data field that records the sign of the number, as
in the following code:
public class Int {
//Records if Int negative/nonnegative
boolean negative=false;
//Digits are stored as decimal digits,
//highest order digit first
int[] digits;
//Declare zero constant
final public static Int ZERO=new Int();
//Records position of 0 (zero) in the
//character set
final private static int zeroPos='0';
Search WWH ::




Custom Search