from matplotlib import pyplot as plt

def main():
    bit = list()
    start = 2
    lfsr = start
    i = 1
    values = []
    taps = [5, 4]
    # taps = [5, 4, 2, 1]
    while True:
        # fb = ((lfsr >> 5) ^ (lfsr >> 4) & 1)
        fb = 0
        for tap in taps:
            fb ^= ((lfsr >> tap) & 1)


        lfsr = ((lfsr << 1) + fb) & (2 ** 6 - 1)
        bit.append(fb)
        values.append(lfsr)
        print(i, lfsr, fb, bin(lfsr))
        if lfsr == start:
            print('repeat pattern length', i)
            break
        i = i + 1

    print('Duplicate Check', len(values), len(set(values)))


    # bit = [float(i) for i in bit]

    # for i in range(2 ** 6 - 1):
    #     bit[i] = 2 * (bit[i] - 0.5)

    plt.plot(values)
    plt.title('sequence')
    plt.show()
    print("done!")



if __name__ == '__main__':
    main()