From b977886d8c323e1e06eccd9d58be9af7b3164c7e Mon Sep 17 00:00:00 2001 From: Pierre LALET <pierre.lalet@cea.fr> Date: Thu, 7 Apr 2016 08:26:24 +0200 Subject: [PATCH] Python 2.5: fallback implementation for gcd() without pycrypto This was reported by @AmedeoSapio in #68 --- scapy/layers/ipsec.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scapy/layers/ipsec.py b/scapy/layers/ipsec.py index b609b947..6138e896 100644 --- a/scapy/layers/ipsec.py +++ b/scapy/layers/ipsec.py @@ -41,7 +41,22 @@ True import socket import struct -from Crypto.Util.number import GCD as gcd +try: + from Crypto.Util.number import GCD as gcd +except ImportError: + try: + from fractions import gcd + except ImportError: + def gcd(a, b): + """Fallback implementation when Crypto is missing, and fractions does + not exist (Python 2.5) + + """ + if b > a: + a, b = b, a + c = a % b + return b if c == 0 else gcd(c, b) + from scapy.data import IP_PROTOS -- GitLab