Advertisement
Chris_M_Thomasson

Reverse Fractal Iteration Quinary Encoding

Jul 13th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. # Chris M. Thomasson 2016
  2. # Reverse Fractal Iteration Quinary Encoding
  3. # Does NOT work with fractional powers yet!
  4. # Thats coming...
  5.  
  6.  
  7. import math;
  8.  
  9.  
  10. # Complex Roots
  11. def croots(z, p):
  12.     l = math.sqrt(z.real**2 + z.imag**2);
  13.     s = l**(1.0 / p);
  14.     a = math.atan2(z.imag, z.real) / p;
  15.  
  16.     n = math.ceil(math.fabs(p));
  17.     astep = (math.pi * 2.0) / p;
  18.  
  19.     result = [];
  20.  
  21.     for i in range(n):
  22.         r = complex(math.cos(a + astep * i) * s,
  23.                     math.sin(a + astep * i) * s);
  24.         # print(r);
  25.         result.append(r);
  26.  
  27.     return result;
  28.  
  29.  
  30. # Find Root
  31. def froots(z, r):
  32.     n = 0;
  33.     for i in r:
  34.         d = z - i;
  35.         l = math.sqrt(d.real**2 + d.imag**2);
  36.         if l < 0.000001: return n;
  37.         n = n + 1;
  38.     return -1;
  39.  
  40.  
  41. # Encrypt quinary stream
  42. def encrypt_quinary(z, c, p):
  43.     n = 0;
  44.     for i in p:
  45.         r = croots(z - c, 5.0);
  46.         z = r[int(i)];
  47.         print("z[" + str(n) + "]:(" + i + "):" + str(z));
  48.         n = n + 1;
  49.     return z;
  50.  
  51. # Decrypt quinary stream
  52. def decrypt_quinary(z, c, n):
  53.     s = "";
  54.     for i in range(n):
  55.         f = z**5.0 + c;
  56.         r = croots(f - c, 5.0);
  57.         b = froots(z, r);
  58.         s += str(b);
  59.         print("z[" + str(n - i - 1) + "]:(" + str(b) + "):" + str(z));
  60.         z = f;
  61.     s = s[::-1];
  62.     return s;
  63.        
  64.          
  65.  
  66.  
  67. # The secret key (c), and origin point (z)
  68. c = (-.75+.09j);
  69. z = (0+0j);
  70. pt0 = "0123443210";
  71.  
  72. n = len(pt0);
  73.  
  74. # Display our environment.
  75. print("c:" + str(c));
  76. print("z:" + str(z));
  77. print("n:" + str(n));
  78. print("pt0:" + str(pt0));
  79. print("");
  80.  
  81.  
  82. print("Encrypt Quinary: " + str(n) + " Iterations");
  83. print("_________________________________________");
  84. ct = encrypt_quinary(z, c, pt0);
  85. print("_________________________________________");
  86. print("");
  87.  
  88.  
  89. print("Decrypt Quinary: " + str(n) + " Iterations");
  90. print("_________________________________________");
  91. pt1 = decrypt_quinary(ct, c, n);
  92. print("_________________________________________");
  93. print("");
  94.  
  95.  
  96. print("pt1:" + pt1);
  97.  
  98. if pt0 != pt1: print("DATA CORRUPTED!!! ;^o");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement