Cryptography Reference
In-Depth Information
while (top2>=0) {
sum=other.digits[top2]+carry;
if (sum>9) {sum%=10; carry=1;} else carry=0;
answer.digits[top3]=sum;
top2--;top3--;
}
answer.digits[top3]=carry;
} else {
while (top1>=0) {
sum=this.digits[top1]+carry;
if (sum>9) {sum%=10; carry=1;} else carry=0;
answer.digits[top3]=sum;
top1--;top3--;
}
answer.digits[top3]=carry;
}
return answer;
}
private Int subtractDigits(Int other) {
Int answer=new Int();
Int copy=new Int(this);
answer.digits=new int[this.digits.length];
int top1=this.digits.length-1;
int top2=other.digits.length-1;
while (top2>=0) {
if (copy.digits[top1]<other.digits[top2]) {
borrow(copy,top1-1);
copy.digits[top1]+=10;
}
answer.digits[top1]=copy.digits[top1]-other.digits[top2];
top1--; top2--;
}
while (top1>=0) {
answer.digits[top1]=copy.digits[top1];
top1--;
}
return answer;
}
//Method to “borrow” for subtraction
private void borrow(Int n,int pos) {
while (n.digits[pos]==0) {
n.digits[pos]=9;
pos--;
}
Search WWH ::




Custom Search