小编Ego*_*rov的帖子

如何在python 3.7中加密和解密字符串?

我发现了同样的问题.但PyCrypto并没有在python 3.6.5和3.7.0上安装.

所以,我实现了某种类似Gronsfeld的密码.我知道,这很糟糕,但我可以简单地用密码加密和解密字符串

def encrypt(string, password):
    int_list = []
    password_len = len(password)
    for cnt, sym in enumerate(string):
        password_sym = password[cnt % password_len]
        int_list.append(ord(sym)-ord(password_sym))
    return int_list

# got some list which contain mine key to Todoist api, yes, this can be bruteforced, but same as any other API key
>>> [-20, -20, -50, -14, -61, -54, 2, 0, 32, 27, -51, -21, -54, -53, 4, 3, 29, -14, -51, 29, -10, -6, 1, 4, 28,
       29, -55, -17, -59, -42, …
Run Code Online (Sandbox Code Playgroud)

python security python-3.x

6
推荐指数
1
解决办法
5122
查看次数

为什么类变量从方法和外部读取是不同的?

所以,我创建了一些课程

class Some:
    @classmethod
    def __init__(cls, somevar):
        cls.somevar = somevar

    @classmethod
    def read(cls):
        return cls.somevar
Run Code Online (Sandbox Code Playgroud)

现在我尝试在外部设置变量并从类中读取它:

instance = Some([1, 2, 3])
instance.somevar = [4, 5, 6]
print(instance.read())

>>>> [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

但是在类外调用相同的命名变量会给我预期的输出,

print(instance.somevar)
>>>> [4, 5, 6]
Run Code Online (Sandbox Code Playgroud)

我对OOP的误解是什么?

编辑

我的目标是创建Some具有自己值的多个实例.

python oop

2
推荐指数
1
解决办法
61
查看次数

标签 统计

python ×2

oop ×1

python-3.x ×1

security ×1