ex09 利用列表隐藏信息与找回信息

描述

题源

说明

  • 题中带有一条极长的字符串,不方便写在此随笔中
  • 我心血来潮,也改编一下

要求

  1. 创建一串类似 $%#@^ 的乱码
  2. 将字符串 "I am not a smart man, but I know what love is." 中的字符按顺序插入乱码
  3. 统计新乱码中各字符的个数
  4. 把字符串找出来

程序

from random import choice, randint

string = "I am not a smart man, but I know what love is."

# 写入
symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')']
garbled = [choice(symbols) for _ in range(520)]
pos = 0
interval = 520 // len(string)
for s in string:
    pos += randint(1, interval)
    garbled.insert(pos, s)

# 读取
first = {}
for e in garbled:
    first[e] = first.get(e, 0) + 1
print(first)

for s in garbled:
    if first[s] < 15:
        print(s, end='')
print()
  • 运行截图(结果不唯一)

    Valentine

原文地址:https://www.cnblogs.com/yorkyu/p/10374929.html