human
Solve in Python:
[The Vigenère cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) is a classic cipher that was thought to be "unbreakable" for three centuries. We now know that this is not so and it can actually be broken pretty easily.

**How the Vigenère cipher works**:

The basic concept is that you have a `message` and a `key`, and each character in the `message` is encrypted using a character in the `key`, by applying a Caesar shift. The key is recycled as many times as needed.

You might want to try [this kata](https://www.codewars.com/kata/vigenere-cipher-helper) first, which focuses on the encryption and decryption processes.

## Well how do we break it?

The first thing we have to do is determine the **length of the key** that was used to encrypt the message.

Write a function that takes some cipher text and a maximum possible key length and returns the length of the key that was used in the encryption process.

**Note:** We don't care about what characters are in the key -- only how many of them there are.

---

Any feedback (and suggestions) would be much appreciated

*This kata is based on one of the programming assignments in [Prof. Jonathan Katz's course on cryptography](https://www.coursera.org/course/cryptography) given on Coursera*

Write me a Python program to determine the **length of the key** that was used to encrypt the message?
assistant
#Here is Python program to determine the **length of the key** that was used to encrypt the message.

from functools import reduce
import itertools

def most_common(lst):
    return max(set(lst), key=lst.count)

def factors(n):    
    return list(set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def gcd_list(alist):
    def gcd(a, b):
        while b > 0:
            a, b = b, a % b
        return a

    result = alist[0]
    for i in alist[1:]:
        result = gcd(result, i)

    return result


def common_subs(alist):
    to_return = []
    for i in alist:
        for j in alist:
            if i != j:
                to_return.append(abs(i-j))
    return to_return
    
#print(common_subs([100,3,4]))    

def get_key_length(cipher_text,max_key_length):
    dis = []
    for pos,char in enumerate(cipher_text):
        if pos == len(cipher_text)-1:
            pass
        else:
            dis.append([cipher_text[pos]+cipher_text[pos+1],pos])
            
    alls = []
    for di in dis:
        if [x[0] for x in dis].count(di[0]) != 1:
            a = [x[1] for x in dis if x[0] == di[0]]
            #print(a)
            #print(common_subs(a))
            #print(gcd_list(common_subs(a)))
            alls.append(gcd_list(common_subs(a)))
    print('a')
    return most_common([x for x in alls if x != 1])