I mentioned that we can use higher powers to encode more symbols than binary. Well, here is a quick example that uses quinary. It can encode five symbols (0, 1, 2, 3, 4). This means that we cannot use the sign of the root go get at the data anymore. Take a close look at the (encrypt_quinary) and (decrypt_quinary) functions. To decrypt we need to forward iterate (z^5+c) into (f), get (f - c)'s 5 roots, then find which one is closest to (z). This indexes directly into the 5 symbols. We then set z to f, and continue. I implemented an example in Python 3, check this out:
http://pastebin.com/mX0SG5kM__________________________________________________
# 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");
__________________________________________________
I get an output of:
__________________________________________________
c:(-0.75+0.09j)
z:0j
n:10
pt0:0123443210
Encrypt Quinary: 10 Iterations
_________________________________________
z[0]:(0):(0.9451685793824627-0.02258038810019985j)
z[1]:(1):(0.35756437868104407+1.0527521186191984j)
z[2]:(2)
-0.9551091176839042+0.5035767961580385j)
z[3]:(3)
-0.4377271477816378-0.7365056013652742j)
z[4]:(4):(0.07042003964910772-0.9729932435136784j)
z[5]:(4):(0.13904278139280354-1.0515670852882053j)
z[6]:(3)
-0.9711340891379753-0.46491924409551966j)
z[7]:(2)
-0.4734106347448234+0.7678784601618063j)
z[8]:(1):(0.0727237491661892+0.9367275179453214j)
z[9]:(0):(1.0205658310765122+0.16465132844438568j)
_________________________________________
Decrypt Quinary: 10 Iterations
_________________________________________
z[9]:(0):(1.0205658310765122+0.16465132844438568j)
z[8]:(1):(0.0727237491661894+0.9367275179453213j)
z[7]:(2)
-0.4734106347448228+0.7678784601618056j)
z[6]:(3)
-0.9711340891379746-0.46491924409551677j)
z[5]:(4):(0.1390427813927817-1.0515670852882062j)
z[4]:(4):(0.0704200396489919-0.9729932435137526j)
z[3]:(3)
-0.43772714778204685-0.7365056013657469j)
z[2]:(2)
-0.9551091176843745+0.5035767961596559j)
z[1]:(1):(0.3575643786924483+1.0527521186182027j)
z[0]:(0):(0.9451685793976057-0.022580388186342365j)
_________________________________________
pt1:0123443210
__________________________________________________
Is this working for you?
FWIW, you run, play with the code here:
https://repl.itMany thanks to +Juaquin Anderson for the original idea of storing binary! Wow. :^D