Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Chris M. Thomasson 2016
- # Reverse Fractal Iteration Quinary Encoding
- # Does NOT work with fractional powers yet!
- # Thats coming...
- import math;
- # Complex Roots
- def croots(z, p):
- l = math.sqrt(z.real**2 + z.imag**2);
- s = l**(1.0 / p);
- a = math.atan2(z.imag, z.real) / p;
- n = math.ceil(math.fabs(p));
- astep = (math.pi * 2.0) / p;
- result = [];
- for i in range(n):
- r = complex(math.cos(a + astep * i) * s,
- math.sin(a + astep * i) * s);
- # print(r);
- result.append(r);
- return result;
- # Find Root
- def froots(z, r):
- n = 0;
- for i in r:
- d = z - i;
- l = math.sqrt(d.real**2 + d.imag**2);
- if l < 0.000001: return n;
- n = n + 1;
- return -1;
- # Encrypt quinary stream
- def encrypt_quinary(z, c, p):
- n = 0;
- for i in p:
- r = croots(z - c, 5.0);
- z = r[int(i)];
- print("z[" + str(n) + "]:(" + i + "):" + str(z));
- n = n + 1;
- return z;
- # Decrypt quinary stream
- def decrypt_quinary(z, c, n):
- s = "";
- for i in range(n):
- f = z**5.0 + c;
- r = croots(f - c, 5.0);
- b = froots(z, r);
- s += str(b);
- print("z[" + str(n - i - 1) + "]:(" + str(b) + "):" + str(z));
- z = f;
- s = s[::-1];
- return s;
- # The secret key (c), and origin point (z)
- c = (-.75+.09j);
- z = (0+0j);
- pt0 = "0123443210";
- n = len(pt0);
- # Display our environment.
- print("c:" + str(c));
- print("z:" + str(z));
- print("n:" + str(n));
- print("pt0:" + str(pt0));
- print("");
- print("Encrypt Quinary: " + str(n) + " Iterations");
- print("_________________________________________");
- ct = encrypt_quinary(z, c, pt0);
- print("_________________________________________");
- print("");
- print("Decrypt Quinary: " + str(n) + " Iterations");
- print("_________________________________________");
- pt1 = decrypt_quinary(ct, c, n);
- print("_________________________________________");
- print("");
- print("pt1:" + pt1);
- if pt0 != pt1: print("DATA CORRUPTED!!! ;^o");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement