In [21]:
import random

fh = open(r'd:\Temp\单词.txt')
text = fh.read()
fh.close()

words = []
words = text.split()

fh = open(r'd:\Temp\words_secret.txt','w')
fh.writelines(words)
fh.close()

words_secret = []
words_secret = text.split()
print(words_secret)
print('\n')

def random_number_list():
    num_list = []
    for n in range(9):
        num = random.randint(0,9)
        num_list.append(num)
    return num_list

def get_ch_table(line):
    ch_table = []
    for ch in line:
        if ch not in words_secret:
            ch_table.append(ch)
    print('字母表',ch_table)
    print('\n')
    return ch_table
fh = open(r'd:\Temp\单词.txt')
text = fh.read()
chs = get_ch_table(text.replace(r'\n', ''))

len_list = []
code_list = []
i = 0
for ch in words_secret:
    number = len(words_secret[i])
    len_list.append(number)
    i += 1
print('单词长度:',len_list)
print('\n')

print('初始密码表')
for j in range(len(words_secret)):
    code_list = random_number_list()
    code_list.append(len_list[j]-1)
    print(code_list)


['neuron', 'nurture', 'Portuguese', 'resemblance', 'eclipse', 'anticipate', 'literal', 'pathology', 'diciple', 'sin', 'resurrection', 'breed', 'exploit', 'denotation', 'revenue', 'prestige', 'integrity']


字母表 ['n', 'e', 'u', 'r', 'o', 'n', ' ', 'n', 'u', 'r', 't', 'u', 'r', 'e', ' ', 'P', 'o', 'r', 't', 'u', 'g', 'u', 'e', 's', 'e', ' ', 'r', 'e', 's', 'e', 'm', 'b', 'l', 'a', 'n', 'c', 'e', ' ', 'e', 'c', 'l', 'i', 'p', 's', 'e', ' ', 'a', 'n', 't', 'i', 'c', 'i', 'p', 'a', 't', 'e', ' ', 'l', 'i', 't', 'e', 'r', 'a', 'l', ' ', 'p', 'a', 't', 'h', 'o', 'l', 'o', 'g', 'y', ' ', 'd', 'i', 'c', 'i', 'p', 'l', 'e', ' ', 's', 'i', 'n', ' ', 'r', 'e', 's', 'u', 'r', 'r', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'b', 'r', 'e', 'e', 'd', ' ', 'e', 'x', 'p', 'l', 'o', 'i', 't', ' ', 'd', 'e', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', ' ', 'r', 'e', 'v', 'e', 'n', 'u', 'e', ' ', 'p', 'r', 'e', 's', 't', 'i', 'g', 'e', ' ', 'i', 'n', 't', 'e', 'g', 'r', 'i', 't', 'y']


单词长度: [6, 7, 10, 11, 7, 10, 7, 9, 7, 3, 12, 5, 7, 10, 7, 8, 9]


初始密码表
[9, 8, 3, 5, 1, 6, 1, 1, 6, 5]
[4, 7, 3, 5, 7, 6, 8, 7, 3, 6]
[8, 7, 3, 6, 8, 8, 2, 9, 9, 9]
[0, 7, 8, 2, 7, 2, 2, 1, 2, 10]
[8, 8, 4, 9, 2, 1, 9, 2, 3, 6]
[6, 6, 8, 2, 0, 0, 1, 3, 3, 9]
[2, 4, 1, 7, 5, 4, 4, 9, 5, 6]
[2, 5, 6, 0, 6, 7, 9, 6, 8, 8]
[8, 3, 7, 9, 3, 1, 5, 4, 5, 6]
[9, 5, 6, 1, 4, 0, 6, 7, 5, 2]
[8, 3, 5, 4, 9, 4, 3, 5, 2, 11]
[5, 9, 8, 3, 7, 8, 7, 1, 8, 4]
[1, 5, 1, 0, 9, 7, 0, 3, 8, 6]
[5, 0, 3, 6, 2, 4, 6, 1, 0, 9]
[0, 4, 0, 9, 7, 0, 1, 7, 9, 6]
[6, 7, 3, 3, 7, 0, 6, 2, 9, 7]
[1, 3, 4, 5, 4, 4, 2, 8, 5, 8]