eggcrypt 2.1.0__tar.gz → 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eggcrypt
3
- Version: 2.1.0
3
+ Version: 3.1.0
4
4
  Summary: A pretty secure (yet inneficient) encryption program. Has key(), hash(), encrypt() and decrypt().
5
5
  Author: Egglord
6
6
  License: MIT
@@ -0,0 +1,175 @@
1
+ from functools import lru_cache
2
+ def hash2(txt):
3
+ txt=str(txt)
4
+ data=txt.encode()
5
+ m=0xFFFFFFFFFFFFFFFF
6
+ h=0x9E3779B97F4A7C15^len(data)
7
+ i=0
8
+ while i+8<=len(data):
9
+ x=int.from_bytes(data[i:i+8],"little")
10
+ h^=x*0x9E3779B185EBCA87&m
11
+ h=((h<<31)|(h>>33))&m
12
+ h*=0xC2B2AE3D27D4EB4F&m
13
+ i+=8
14
+ x=0
15
+ for j,b in enumerate(data[i:]):
16
+ x|=b<<(j*8)
17
+ h^=x*0x165667B19E3779F9&m
18
+ h^=h>>33
19
+ h=h*0xFF51AFD7ED558CCD&m
20
+ h^=h>>33
21
+ h=h*0xC4CEB9FE1A85EC53&m
22
+ h^=h>>33
23
+ return str(h)
24
+ @lru_cache(maxsize=512)
25
+ def makesbox(key):
26
+ prev=hash2(key)
27
+ stream=[]
28
+ while len(stream)<256:
29
+ n=int(prev,36)
30
+ for _ in range(50):
31
+ stream.append(n&255)
32
+ n>>=8
33
+ if len(stream)>=256:
34
+ break
35
+ prev=hash2(prev)
36
+ unused=list(range(256))
37
+ sbox=[]
38
+ for i in range(255,-1,-1):
39
+ b=stream.pop()% (i+1)
40
+ sbox.append(unused.pop(b))
41
+ return sbox
42
+ def xor_text(txt,key):
43
+ key=str(key)
44
+ out=""
45
+ for i,ch in enumerate(txt):
46
+ out+=chr(ord(ch)^ord(key[i%len(key)]))
47
+ return out
48
+ def diffuse(data):
49
+ data=[ord(c) for c in data]
50
+ for i in range(1,len(data)):
51
+ data[i]^=data[i-1]
52
+ return "".join(chr(x) for x in data)
53
+ def undiffuse(data):
54
+ data=[ord(c) for c in data]
55
+ for i in range(len(data)-1,0,-1):
56
+ data[i]^=data[i-1]
57
+ return "".join(chr(x) for x in data)
58
+ def rol(x):
59
+ return ((x<<1)|(x>>7))&0xff
60
+ def diffuse2(data):
61
+ data=[ord(c) for c in data]
62
+ for i in range(1,len(data)):
63
+ data[i]^=rol(data[i-1])
64
+ return "".join(chr(x) for x in data)
65
+ def undiffuse2(data):
66
+ data=[ord(c) for c in data]
67
+ for i in range(len(data)-1,0,-1):
68
+ data[i]^=rol(data[i-1])
69
+ return "".join(chr(x) for x in data)
70
+ def round_sbox(key,r):
71
+ round_key=xor_text(str(key),hash2(str(key)+str(r*0x9E3779B97F4A7C15)))
72
+ return makesbox(round_key)
73
+ @lru_cache(maxsize=512)
74
+ def roundkey(key,r):
75
+ return int(hash2(str(key)+str(r*0x9E3779B97F4A7C15)),36)
76
+ def permute(data, perm):
77
+ return "".join(data[i] for i in perm)
78
+ def make_perm(n, key=7):
79
+ perm=[]
80
+ used=set()
81
+ x=key&0x7fffffff
82
+ for _ in range(n):
83
+ x=(x*1103515245+12345)&0x7fffffff
84
+ x=int.from_bytes(xor_text(str(x),hash2(x*0x9E3779B185EBCA87)).encode(),"big")
85
+ pos=x%n
86
+ while pos in used:
87
+ pos=(pos+1)%n
88
+ used.add(pos)
89
+ perm.append(pos)
90
+ return perm
91
+ def inverse_perm(perm):
92
+ inv=[0]*len(perm)
93
+ for new_pos, old_pos in enumerate(perm):
94
+ inv[old_pos]=new_pos
95
+ return inv
96
+ def encrypt(txt,key):
97
+ for r in range(10):
98
+ txt=xor_text(txt,roundkey(key,r))
99
+ sbox=round_sbox(key,r)
100
+ out=""
101
+ for ch in txt:
102
+ out+=chr(sbox[ord(ch)])
103
+ txt=diffuse2(out)
104
+ txt=diffuse(txt)
105
+ perm=make_perm(len(txt), roundkey(key,r))
106
+ txt=permute(txt,perm)
107
+ for r in range(22):
108
+ txt=xor_text(txt, hash2(hash2(r)+hash2(key)))
109
+ txt=diffuse2(txt)
110
+ final_perm =make_perm(len(txt), roundkey(key,999))
111
+ txt=permute(txt,final_perm)
112
+ return txt
113
+ def decrypt(txt,key):
114
+ final_perm=make_perm(len(txt),roundkey(key,999))
115
+ txt=permute(txt,inverse_perm(final_perm))
116
+ txt=undiffuse2(txt)
117
+ for r in range(21,-1,-1):
118
+ txt=xor_text(txt,hash2(hash2(r)+hash2(key)))
119
+ for r in range(9,-1,-1):
120
+ perm=make_perm(len(txt),roundkey(key,r))
121
+ txt=permute(txt, inverse_perm(perm))
122
+ txt=undiffuse(txt)
123
+ txt=undiffuse2(txt)
124
+ sbox=round_sbox(key,r)
125
+ inv=[0]*256
126
+ for i,v in enumerate(sbox):
127
+ inv[v]=i
128
+ out=""
129
+ for ch in txt:
130
+ out+=chr(inv[ord(ch)])
131
+ txt=xor_text(out,roundkey(key,r))
132
+ return txt
133
+ def key():
134
+ import time
135
+ seed=1
136
+ for i in range(int(time.time()*10000)%100):
137
+ a=str(time.time()*10000)
138
+ a=a[0:10]
139
+ a=int(a)
140
+ seed=int(seed*a+(round(seed^a)))
141
+ return seed
142
+ def hash(inp):
143
+ inp=str(inp)
144
+ H=[0x243f6a8885a308d3,0x13198a2e03707344,0xa4093822299f31d0,0x082efa98ec4e6c89]
145
+ for i,c in enumerate(inp):
146
+ x=ord(c)+(i<<8)
147
+ j=i%4
148
+ H[j]^=x
149
+ H[j]=(H[j]*0x100000001b3)&0xffffffffffffffff
150
+ H[(j+1)%4]^=H[j]>>17
151
+ key_str=''.join(f'{x:016x}' for x in H)
152
+ tot=sum((i+1)*ord(c) for i,c in enumerate(key_str))
153
+ for i in inp:
154
+ tot^=ord(i)
155
+ out=""
156
+ for i in key_str:
157
+ v=int(i,16)
158
+ out+=str(v+((tot*v)%256))
159
+ o=""
160
+ for i in out:o+=chr((int(i)+tot)%256)
161
+ out=""
162
+ for i in range(len(o)-1):out+=str(i*tot+ord(o[i]))
163
+ for n in map(int,[out[i:i+2] for i in range(0,len(out),2)]):o+=chr(n+32)
164
+ if len(out)%2:o+=chr(int(out[-1])*21)
165
+ o=o.lstrip("0123456789")
166
+ h=0
167
+ for c in o:
168
+ h^=ord(c)
169
+ h=((h<<13)|(h >> 243))&((1<<256)-1)
170
+ h=(h*0x9e3779b97f4a7c15)&((1<<256)-1)
171
+ chars="0123456789abcdefghijklmnopqrstuvwxyz"
172
+ x=""
173
+ while h:x=chars[h%36]+x;h//=36
174
+ out=x.zfill(50)
175
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eggcrypt
3
- Version: 2.1.0
3
+ Version: 3.1.0
4
4
  Summary: A pretty secure (yet inneficient) encryption program. Has key(), hash(), encrypt() and decrypt().
5
5
  Author: Egglord
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "eggcrypt"
7
- version = "2.1.0"
7
+ version = "3.1.0"
8
8
  description = "A pretty secure (yet inneficient) encryption program. Has key(), hash(), encrypt() and decrypt()."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="egg",
5
- version="2.1.0",
5
+ version="3.1.0",
6
6
  packages=find_packages(),
7
7
  description="A pretty secure (yet inneficient) encryption program.",
8
8
  author="Egglord",
@@ -1,58 +0,0 @@
1
- def encrypt(txt,key):
2
- data=""
3
- for i,ch in enumerate(txt):
4
- value=ord(ch)^ord(key[i%len(key)])
5
- data+=f"{value:03d}"
6
- return "".join(chr(int(data[i:i+3])) for i in range(0,len(data),3))
7
- def decrypt(txt,key):
8
- data=""
9
- for ch in txt:
10
- data+=f"{ord(ch):03d}"
11
- result=""
12
- nums=[int(data[i:i+3]) for i in range(0,len(data),3)]
13
- for i,value in enumerate(nums):
14
- result+=chr(value^ord(key[i%len(key)]))
15
- return result
16
- def key():
17
- import time
18
- seed=1
19
- for i in range(int(time.time()*10000)%100):
20
- a=str(time.time()*10000)
21
- a=a[0:10]
22
- a=int(a)
23
- seed=int(seed*a+(round(seed^a)))
24
- return seed
25
- def hash(inp):
26
- inp=str(inp)
27
- H=[0x243f6a8885a308d3,0x13198a2e03707344,0xa4093822299f31d0,0x082efa98ec4e6c89]
28
- for i,c in enumerate(inp):
29
- x=ord(c)+(i<<8)
30
- j=i%4
31
- H[j]^=x
32
- H[j]=(H[j]*0x100000001b3)&0xffffffffffffffff
33
- H[(j+1)%4]^=H[j]>>17
34
- key_str=''.join(f'{x:016x}' for x in H)
35
- tot=sum((i+1)*ord(c) for i,c in enumerate(key_str))
36
- for i in inp:
37
- tot^=ord(i)
38
- out=""
39
- for i in key_str:
40
- v=int(i,16)
41
- out+=str(v+((tot*v)%256))
42
- o=""
43
- for i in out:o+=chr((int(i)+tot)%256)
44
- out=""
45
- for i in range(len(o)-1):out+=str(i*tot+ord(o[i]))
46
- for n in map(int,[out[i:i+2] for i in range(0,len(out),2)]):o+=chr(n+32)
47
- if len(out)%2:o+=chr(int(out[-1])*21)
48
- o=o.lstrip("0123456789")
49
- h=0
50
- for c in o:
51
- h^=ord(c)
52
- h=((h<<13)|(h >> 243))&((1<<256)-1)
53
- h=(h*0x9e3779b97f4a7c15)&((1<<256)-1)
54
- chars="0123456789abcdefghijklmnopqrstuvwxyz"
55
- x=""
56
- while h:x=chars[h%36]+x;h//=36
57
- out=x.zfill(50)
58
- return out
File without changes
File without changes
File without changes
File without changes