Advertisement
Jhynjhiruu

Untitled

May 2nd, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. class encFile():
  2.     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
  3.     def c(q,d): # ↑ Inits variables
  4.         e=[len(d),*[ord(i)for i in d]]
  5.         e.append(sum(e))
  6.         return e
  7.     def l(q):
  8.         q.ff.append(q.ff.pop(0)+1.75) # Formats key properly
  9.         return q.ff[-1]
  10.     def m(q,n):return q.b(n+0.1)%256 # Rounds given value (adds 0.1 so 0.5 goes up) and constrains
  11.     def o(q,p,s):
  12.         q.ff,u,v=q.c(p),q.n(),0
  13.         for i in q.n(s):
  14.             x=v+q.l()
  15.             y=q.m(i+q.b(x+0.1))
  16.             u.append(y)
  17.             v=x+y
  18.         return u
  19.     def r(q,s,t):
  20.         q.ff,z,aa=q.c(s),q.n(),0
  21.         for i in t:
  22.             bb,cc=aa+q.l(),i
  23.             aa=bb+cc
  24.             z.append(q.m(cc-q.b(bb+0.1)))
  25.         return z
  26.     def j(q): # 'readbytes' - reads data from file, decrypts, returns
  27.         if not q.d or q.force:
  28.             try:f=q.n(q.e(q.file,"rb").read())
  29.             except q.p as e:
  30.                 if q.create:
  31.                     q.e(q.file,"wb").close()
  32.                     return q.f
  33.                 raise q.h("{} doesn't exist\nError: {}".format(q.file,e))
  34.             q.d=q.r(q.key,f)
  35.         return q.d
  36.     def w(q): # 'read' - reads data from file, decrypts, decodes, returns
  37.         try:return q.j().decode()
  38.         except q.p as e:raise q.h("{} contains binary data, not text\nError: {}".format(q.file, e))
  39.     def x(q,p): # 'write' - takes data, encrypts and writes to file
  40.         if p!=q.d or q.force:
  41.             try:q.e(q.file).close()
  42.             except q.p as e:
  43.                 if q.create:pass
  44.                 raise q.h("{} doesn't exist\nError: {}".format(q.file,e))
  45.             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")))
  46.             q.d=q.f
  47.     def z(q):return q.j().decode().split("\n") # 'readlines' - reads/decrypts data from file, splits at newline, returns
  48.     def y(q): # 'readline' - iterates through lines in file every time it's called
  49.         if not q.k:q.k=iter(q.z())
  50.         try:return next(q.k)
  51.         except:
  52.             q.k=q.f
  53.             return q.y()
  54.     __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