【问题标题】:How I would Add the Int in this Variable to each int in this list我如何将此变量中的 Int 添加到此列表中的每个 int
【发布时间】:2016-08-19 04:01:33
【问题描述】:

我需要将Offset 中的int 添加到Code 中的每个数字中 这就是我如何制作Offset

num1 = (randint(33,126))
num2 = (randint(33,126))
num3 = (randint(33,126))
num4 = (randint(33,126))
num5 = (randint(33,126))
num6 = (randint(33,126))
num7 = (randint(33,126))
num8 = (randint(33,126))
key1 = chr(num1)
key2 = chr(num2)
key3 = chr(num3)
key4 = chr(num4)
key5 = chr(num5)
key6 = chr(num6)
key7 = chr(num7)
key8 = chr(num8)
characterkey = (key1 + key2 + key3 + key4 + key5 + key6 + key7 + key8)
Label(window2, text = characterkey, font = font, bg = "Dim grey", fg = "cyan").place(x = 130, y = 300)
offset = int(num1+num2+num3+num4+num5+num6+num7+num8)
offset = int(offset/8)
offset = int(offset - 32)
print(offset)

我在这里将一个文本文件转换成它的 ASCII 码

Code =" ".join(str(ord(char))for char in readFile)

但是我需要将偏移量添加到代码中的每个转换后的 Ascii 代码中,并且在添加偏移量之后,如果它等于 126 以上,它将减去 94

【问题讨论】:

  • 您能否为变量使用小写名称(参见PEP 8)?

标签: python-3.x encryption int ascii public-key-encryption


【解决方案1】:

我不完全确定你想做什么,但这是我的猜测:

如果您希望能够快速查看它的作用:

Code = " ".join(map(str, [char + offset - 94 if char + offset > 126 else char + offset for i in map(ord, readFile)]))

或者当你关心速度时(因为在上面的例子中 char + offset 被计算了两次):

Code = " ".join(map(str, [(lambda x: x if x <= 126 else x - 94)(char + Offset)) for char in map(ord, readFile)]))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    相关资源
    最近更新 更多