for n_s, s in enumerate(cycle(key_ring)): if n_s < key_begin: continue elif n_s > key_begin+39: break real_key += chr(s)