Skip to content

Instantly share code, notes, and snippets.

@AmirSoleimani
Created November 21, 2018 09:46
Show Gist options
  • Select an option

  • Save AmirSoleimani/c4b7435308fc5a121c4c35cba1e07024 to your computer and use it in GitHub Desktop.

Select an option

Save AmirSoleimani/c4b7435308fc5a121c4c35cba1e07024 to your computer and use it in GitHub Desktop.
GCD - Greatest Common Divisor
package cryptogcd
//GCD Greatest Common Divisor (Factor)
func GCD(a, b int) int {
var Remainder int
for {
Remainder = a % b
a = b
b = Remainder
if b == 0 {
break
}
}
return a
}
@AmirSoleimani
Copy link
Copy Markdown
Author

GCD is known as the greatest common divisor, or greatest common factor (gcf), and is the largest positive integer that divides into two numbers without a remainder. For example, the GCD of 9 and 15 is 3. It is an operation that is used many encryption algorithms

Sample:
9, 15 -> 3
54, 8 -> 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment