From 40ce4b6736d1473d08f135e5bbfa2045f074739a Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 27 Jan 2022 16:05:43 +0000 Subject: [PATCH] Affine.java edited online with Bitbucket --- .../monoSubstitution/Affine.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Affine.java b/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Affine.java index 49770f8..b8ef99f 100644 --- a/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Affine.java +++ b/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Affine.java @@ -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; - } }