Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #41093
| From | "Chris M. Thomasson" <nospam@nospam.nospam> |
|---|---|
| Newsgroups | comp.lang.c++, sci.crypt |
| Subject | Re: Reverse Iteration Fractal Encryption... |
| Date | 2016-02-21 14:30 -0800 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <naddqm$13kk$1@gioia.aioe.org> (permalink) |
| References | <nadaph$pnu$1@gioia.aioe.org> |
Cross-posted to 2 groups.
> "Chris M. Thomasson" wrote in message news:nadaph$pnu$1@gioia.aioe.org...
> Original idea by Juaquin Anderson in the comments of the
> following thread:
> https://plus.google.com/+JuaquinAnderson/posts/L9A3Da8ju3B
[...]
FWIW, here is another c++11 proof of concept program
that can encrypt all byte values:
http://pastebin.com/VsvH3HdE
Some essential further context:
https://plus.google.com/101799841244447089430/posts/6hYWn1YPd2C
This makes sense because there are an infinite number of
different representations of the root tree wrt going down
a positive or negative root during reverse iteration...
example code:
__________________________________________________
/*
Original idea by: Juaquin Anderson, in the comments of the following thread:
https://plus.google.com/+JuaquinAnderson/posts/L9A3Da8ju3B
Implementation by: Chris M. Thomasson
______________________________________________________________________
*/
#include <iostream>
#include <complex>
#include <array>
#include <vector>
#include <climits>
#include <cassert>
#define ESP ((iim_float_t)0.000000001)
typedef double iim_float_t;
typedef std::complex<iim_float_t> complex_t;
typedef std::array<bool, CHAR_BIT> bitchar_t;
struct forward_ret
{
complex_t z;
bitchar_t bc;
};
static unsigned char
bitchar_get(
bitchar_t
);
static complex_t
iterate_reverse(
complex_t,
complex_t,
bitchar_t const&
);
static forward_ret
iterate_forward(
complex_t,
complex_t
);
unsigned char
bitchar_get(
bitchar_t bc
) {
assert(bc.size() == CHAR_BIT);
unsigned char r = 0;
unsigned int b = 1;
for (unsigned int i = 0; i < bc.size(); ++i)
{
if (bc[i]) r = r | b;
b = b << 1;
}
return r;
}
bitchar_t
bitchar_set(
unsigned char n
) {
bitchar_t r = { false };
unsigned int b = 1;
for (unsigned int i = 0; i < r.size(); ++i)
{
r[i] = (n & b) ? true : false;
b = b << 1;
}
return r;
}
complex_t
iterate_reverse(
complex_t z,
complex_t c,
bitchar_t const& bc
) {
assert(bc.size() == CHAR_BIT);
for (std::size_t i = 0; i < CHAR_BIT; ++i)
{
complex_t d = z - c;
iim_float_t l = std::abs(d);
iim_float_t s = std::sqrt(l);
iim_float_t a = std::atan2(d.imag(), d.real()) / 2.0;
iim_float_t r = 0;
if (bc[i]) { r = 1; }
else { r = -1; }
complex_t nz = { r * s * std::cos(a), r * s * std::sin(a) };
if (bc[i] == 1)
{
std::cout << "iterate_reverse:[" << i << "]:("
<< bc[i] << "):(+) = " << nz << std::endl;
}
else
{
std::cout << "iterate_reverse:[" << i << "]:("
<< bc[i] << "):(-) = " << nz << std::endl;
}
z = nz;
}
std::cout << "__________________________________________" << std::endl;
return z;
}
forward_ret
iterate_forward(
complex_t z,
complex_t c
) {
forward_ret ret = { { z },{ false } };
std::cout << "iterate_forward:(origin):" << z << std::endl;
for (std::size_t i = 0; i < CHAR_BIT; ++i)
{
complex_t pz = ret.z;
ret.z = ret.z * ret.z + c;
// check for bit on condition
if (pz.real() > 0.0)
{
// turn the proper bit on...
std::size_t bc_i = CHAR_BIT - (i + 1);
ret.bc[bc_i] = true;
}
iim_float_t l = std::abs(ret.z);
if (l < ESP)
{
std::cout << "iterate_forward:(term):[" << i << "]: " << ret.z
<< std::endl;
break;
}
std::cout << "iterate_forward:[" << i << "]: " << ret.z <<
std::endl;
}
std::cout << "__________________________________________" << std::endl;
return ret;
}
int main()
{
{
// the secret key c
complex_t c = { -0.75, 0.09 };
// the origin of iteration z
complex_t z = { 0.0, 0.0 };
// A bytes to encode, the plaintext pt
std::cout << std::endl <<
"**********************************************************"
<< std::endl;
for (std::size_t pt = 0; pt < UCHAR_MAX + 1; ++pt)
{
std::cout << "encoding pt:" << pt << std::endl;
std::cout << "__________________________________________" <<
std::endl;
// set pt to bitchar_t
bitchar_t pt_bits = bitchar_set(pt);
// Our encoded byte point origin, out ciphertext ct
complex_t ct = iterate_reverse(z, c, pt_bits);
// Our decoded bits and point origin db_z
forward_ret db_z = iterate_forward(ct, c);
// Our decoded byte db, should be equal to plaintext pt.
unsigned char db = bitchar_get(db_z.bc);
if (pt != db)
{
std::cout << "pt:" << pt << " != db:" << (int)db <<
std::endl;
std::cin.get();
assert(pt == db);
}
std::cout << "decoded: pt:" << pt << " == db:" << (int)db <<
std::endl;
std::cout <<
"**********************************************************"
<< std::endl;
}
}
std::cout << std::endl << "__________________________________________"
<< std::endl << "Program Complete!" << std::endl;
std::cin.get();
return 0;
}
__________________________________________________
What do you think of this?
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-02-21 13:38 -0800
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-02-21 14:30 -0800
Re: Reverse Iteration Fractal Encryption... Öö Tiib <ootiib@hot.ee> - 2016-02-21 17:09 -0800
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-02-23 12:09 -0800
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-02-23 11:32 -0800
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-02-23 12:42 -0800
Re: Reverse Iteration Fractal Encryption... Peter Fairbrother <peter@tsto.co.uk> - 2016-06-26 16:52 +0100
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-27 13:16 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-27 13:21 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-29 19:49 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-30 11:15 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-30 21:26 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-30 23:03 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-06-30 13:23 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-01 14:23 -0700
Re: Reverse Iteration Fractal Encryption... Christian Gollwitzer <auriocus@gmx.de> - 2016-07-02 08:17 +0200
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 12:25 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 12:28 -0700
Re: Reverse Iteration Fractal Encryption... Christian Gollwitzer <auriocus@gmx.de> - 2016-07-02 22:41 +0200
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 14:18 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 15:36 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 12:47 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 14:37 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-02 15:00 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-03 00:36 -0700
Re: Reverse Iteration Fractal Encryption... "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-07-03 01:09 -0700
csiph-web