Affine.java edited online with Bitbucket

This commit is contained in:
2022-01-27 16:05:43 +00:00
parent 9f3e7ff7a3
commit 40ce4b6736

View File

@@ -8,6 +8,8 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
import mattrixwv.NumberAlgorithms;
public class Affine{
private boolean preserveCapitals;
@@ -26,7 +28,7 @@ public class Affine{
}
//Make sure the key is relatively prime to 26 (The number of letters)
if(gcd(key1, 26) != 1){
if(NumberAlgorithms.gcd(key1, 26) != 1){
throw new InvalidKeywordException("Key 1 must be relatively prime to 26");
}
@@ -186,17 +188,4 @@ public class Affine{
public int getKey2(){
return key2;
}
//TODO: Change to my library's version
//This function returns the GCD of the two numbers sent to it
public static int gcd(int num1, int num2){
while((num1 != 0) && (num2 != 0)){
if(num1 > num2){
num1 %= num2;
}
else{
num2 %= num1;
}
}
return num1 | num2;
}
}