日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python对压缩包简单加密_简单文件压缩加密脚本 python

發(fā)布時間:2023/12/20 python 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python对压缩包简单加密_简单文件压缩加密脚本 python 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#coding:utf-8

# version 1.1

# 添加了一個參數(shù),可以指定輪換的值,雖然暴力破解完全沒難度……

import sys

import getopt

import zlib

import base64

from cStringIO import StringIO

_move = 15

_line_sep = "\n"

class TMain:

def __init__(self):

options, args = 0,0

if len(sys.argv) == 1:

self.usage()

try:

options, args = getopt.getopt(sys.argv[1:], 'dm:')

except getopt.GetoptError, err:

print str(err)

self.usage()

global _move

mode = "serialize"

for opt, value in options:

if opt == "-d":

mode = 'deSerialize'

if opt == "-m":

try:

_move = int(value)

if _move < 0 or _move > 128:

print "Specify a value in range [0, 128]"

sys.exit(1)

except ValueError:

# won't effect _move

pass

for filename in args:

f = getattr(self, mode)

s = f(self.readfile(filename))

fout = file(filename + ".out.py", 'wb')

fout.write(s)

fout.close()

print

print "##################################"

print s

def moveCode(self, strobj ):

result = ""

for i in strobj:

pass

def compress(self,strobj):

return zlib.compress(strobj, 9)

def decompress(self,strobj):

return zlib.decompress(strobj)

def serialize(self, strobj ):

'''serialize the string into encoded format'''

strobj = self.compress( strobj )

strobj = base64.standard_b64encode(strobj)

max_char_per_line = 40

c = 0

result = ""

for i in strobj:

c += 1

if c >= max_char_per_line:

c = 1

result += _line_sep

result += hex( ord( i ) #+ _move

)[2:]

return result

def deSerialize(self, strobj ):

strobj = strobj.replace( _line_sep, '' )

result = ""

strlen = len(strobj)

if strlen % 2 != 0 :

raise Exception("Bad value")

for i in xrange( 0, len( strobj ), 2 ):

c = strobj[i:i + 2]

try:

c = chr( int( c, 16 ) #- _move

)

tmp= hex( ord(c))[2:]

result += c

except ValueError, err:

print c, int( c, 16 ), int( c, 16 ) - _move

# for i in result:

# sys.stdout.write(i)

# print

result = base64.standard_b64decode(result)

#return compress(result)

return self.decompress( result )

def readfile(self, filename ):

return open( filename ).read()

def usage(self,):

usage_str= '''

{this_program} [-d] [-m 10] filename

if the -d option is given, program will try to decode file,

otherwise, program will encode file and print the result.

-m specifies the move steps for character,

defaults to 15, notice, remember this value!

you will need it

'''.format( this_program = sys.argv[0])

print usage_str

sys.exit()

def main():

m = TMain()

if __name__ == '__main__':

main()

總結(jié)

以上是生活随笔為你收集整理的python对压缩包简单加密_简单文件压缩加密脚本 python的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。