Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class encFile():
- def a(q,file,key,create=False,force=False):q.file,q.key,q.create,q.force,q.ff,q.g,q.h,q.d,q.k,q.f,q.n,q.p,q.b,q.e=file,key,create,force,[],NotImplementedError,FileNotFoundError,None,None,None,bytearray,Exception,round,open
- def c(q,d): # ↑ Inits variables
- e=[len(d),*[ord(i)for i in d]]
- e.append(sum(e))
- return e
- def l(q):
- q.ff.append(q.ff.pop(0)+1.75) # Formats key properly
- return q.ff[-1]
- def m(q,n):return q.b(n+0.1)%256 # Rounds given value (adds 0.1 so 0.5 goes up) and constrains
- def o(q,p,s):
- q.ff,u,v=q.c(p),q.n(),0
- for i in q.n(s):
- x=v+q.l()
- y=q.m(i+q.b(x+0.1))
- u.append(y)
- v=x+y
- return u
- def r(q,s,t):
- q.ff,z,aa=q.c(s),q.n(),0
- for i in t:
- bb,cc=aa+q.l(),i
- aa=bb+cc
- z.append(q.m(cc-q.b(bb+0.1)))
- return z
- def j(q): # 'readbytes' - reads data from file, decrypts, returns
- if not q.d or q.force:
- try:f=q.n(q.e(q.file,"rb").read())
- except q.p as e:
- if q.create:
- q.e(q.file,"wb").close()
- return q.f
- raise q.h("{} doesn't exist\nError: {}".format(q.file,e))
- q.d=q.r(q.key,f)
- return q.d
- def w(q): # 'read' - reads data from file, decrypts, decodes, returns
- try:return q.j().decode()
- except q.p as e:raise q.h("{} contains binary data, not text\nError: {}".format(q.file, e))
- def x(q,p): # 'write' - takes data, encrypts and writes to file
- if p!=q.d or q.force:
- try:q.e(q.file).close()
- except q.p as e:
- if q.create:pass
- raise q.h("{} doesn't exist\nError: {}".format(q.file,e))
- with q.e(q.file,"wb")as f:f.write(q.o(q.key,q.n(p)if type(p)!=str else p.encode("utf-8")))
- q.d=q.f
- def z(q):return q.j().decode().split("\n") # 'readlines' - reads/decrypts data from file, splits at newline, returns
- def y(q): # 'readline' - iterates through lines in file every time it's called
- if not q.k:q.k=iter(q.z())
- try:return next(q.k)
- except:
- q.k=q.f
- return q.y()
- __init__,read,write,readlines,readline,readbytes=a,w,x,z,y,j # Sets up 'proper' names from shortened ones
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement