Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RIFC CipherPoint Plotter 8/13/2016 by Chris M. Thomasson
- import math;
- import random;
- import copy; # for non-mutable aspects of classes
- #import os;
- from PIL import Image;
- # Complex Absolute Value
- def cabs(z):
- return math.sqrt(z.real**2 + z.imag**2);
- # Complex Argument
- def carg(z):
- return math.atan2(z.imag, z.real);
- # Complex Argument Range [0...PI2]
- def cargr(z):
- a = math.atan2(z.imag, z.real);
- if (a < 0): a += math.pi * 2;
- return a;
- # Complex Roots
- def croots(z, p):
- l = cabs(z);
- s = l**(1.0 / p);
- a = carg(z) / p;
- n = int(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);
- result.append(r);
- return result;
- # 2d Axes
- class ct_axes_2d:
- def __init__(self, xmin, xmax, ymin, ymax):
- self.xmin = xmin;
- self.xmax = xmax;
- self.ymin = ymin;
- self.ymax = ymax;
- def __repr__(self):
- return "(%s, %s, %s, %s)" % (self.xmin, self.xmax, self.ymin, self.ymax)
- def __str__(self): return self.__repr__();
- def width(self): return self.xmax - self.xmin;
- def height(self): return self.ymax - self.ymin;
- # 2d Plane
- class ct_plane_2d:
- def __init__(self, width, height, axes):
- self.axes = copy.copy(axes);
- self.width = width;
- self.height = height;
- self.xstep = self.axes.width() / width;
- self.ystep = self.axes.height() / height;
- self.aratio = height / width;
- def __repr__(self):
- return "(%s, %s, %s, %s, %s, %s)" % (self.axes,
- self.width, self.height,
- self.xstep, self.ystep,
- self.aratio);
- def __str__(self): return self.__repr__();
- def project_to(self, p):
- x = math.floor((p.real - self.axes.xmin) / self.xstep * self.aratio);
- y = math.floor((self.axes.ymax - p.imag) / self.ystep);
- return complex(x, y);
- # RIFC Plotter
- class ct_rjulia:
- def __init__(self, plane):
- self.plane = copy.copy(plane);
- self.image = Image.new("RGB", (plane.width, plane.height));
- self.pixels = self.image.load();
- def __repr__(self):
- return "(%s)" % (self.plane);
- def __str__(self): return self.__repr__();
- def save(self, fname):
- self.image.save(fname, "BMP");
- def set_pixel(self, p, c):
- if (p.real < 0 or p.real >= self.plane.width or
- p.imag < 0 or p.imag >= self.plane.height):
- return False;
- self.pixels[p.real, p.imag] = c;
- return True;
- def set_point(self, p, c):
- pp = self.plane.project_to(p);
- return self.set_pixel(pp, c);
- def compute(self, z, c, p, n):
- for i in range(n):
- r = croots(z - c, p);
- z = r[random.randint(0, len(r) - 1)];
- return z;
- def plot(self, skey, n, ptn, rndn):
- z = skey.z;
- for i in range(n):
- # encrypt ptn plaintext nits
- z = self.compute(z, skey.c_0, skey.p_0, ptn);
- # encrypt rndn random nits using z from plaintext encryption...
- z = self.compute(z, skey.c_1, skey.p_1, rndn);
- # plot the cipherpoint!
- self.set_point(z, (255, 255, 255));
- print("ct_rjulia::plot(%s of %s)\r" % (i, n), end="");
- print("");
- # Secret Key
- class ct_rifc_skey:
- def __init__(self, z, c_0, c_1, p_0, p_1, n, hmkey):
- self.z = z;
- self.c_0 = c_0;
- self.c_1 = c_1;
- self.p_0 = p_0;
- self.p_1 = p_1;
- self.n = n;
- self.hmack = copy.copy(hmkey);
- def __repr__(self):
- return "(%s, %s, %s, %s, %s, %s, %s)" % (self.z, self.c_0, self.c_1, self.p_0, self.p_1, self.n, self.hmack);
- def __str__(self): return self.__repr__();
- # Main Program
- rfrac = ct_rjulia(ct_plane_2d(640, 640, ct_axes_2d(-2, 2, -2, 2)));
- skey = ct_rifc_skey((0+0j), (-.75+.09j), (.1+.8j), 2, 3, 8, "hmac_secret_key");
- print("RIFC Cipherpoint Plotter 8/13/2016 by Chris M. Thomasson\n");
- print("rfrac:%s" % (rfrac));
- print("skey:%s" % (skey));
- rfrac.plot(skey, 12048, 8, 8);
- rfrac.save("output.bmp");
- #os.system("mspaint output.bmp");
Advertisement
Add Comment
Please, Sign In to add comment