code: def __setkey(key):
      
      global C, D, KS, E
  
      shifts = (1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1)
  
      # First, generate C and D by permuting the key. The lower order bit of each
      # 8-bit char is not used, so C and D are only 28 bits apiece.
      for i in range(28):
          C[i] = key[PC1_C[i] - 1]
          D[i] = key[PC1_D[i] - 1]
  
      for i in range(16):
          # rotate
          for k in range(shifts[i]):
              temp = C[0]
  
              for j in range(27):
                  C[j] = C[j + 1]
  
              C[27] = temp
              temp = D[0]
              for j in range(27):
                  D[j] = D[j + 1]
  
              D[27] = temp
  
          # get Ki. Note C and D are concatenated
          for j in range(24):
              KS[i][j] = C[PC2_C[j] - 1]
              KS[i][j + 24] = D[PC2_D[j] - 28 - 1]
  
      # load E with the initial E bit selections
      for i in range(48):
          E[i] = e2[i]
docs: Set up the key schedule from the encryption key.