Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #64884 > unrolled thread

Fun/Funny Fractal Encryption...

Started by"Chris M. Thomasson" <nospam@nospam.nospam>
First post2015-07-07 17:08 -0700
Last post2015-08-22 22:49 -0700
Articles 13 on this page of 33 — 7 participants

Back to article view | Back to comp.lang.c


Contents

  Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-07 17:08 -0700
    Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-08 01:12 +0100
      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-07 17:19 -0700
        Re: Fun/Funny Fractal Encryption... Robert Wessel <robertwessel2@yahoo.com> - 2015-07-07 22:29 -0500
          Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-07 22:43 -0700
            Re: Fun/Funny Fractal Encryption... Robert Wessel <robertwessel2@yahoo.com> - 2015-07-08 03:23 -0500
            Re: Fun/Funny Fractal Encryption... James Kuyper <jameskuyper@verizon.net> - 2015-07-08 07:36 -0400
              Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-08 12:52 +0100
              Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-08 11:10 -0700
                Re: Fun/Funny Fractal Encryption... James Kuyper <jameskuyper@verizon.net> - 2015-07-08 14:46 -0400
                  Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-08 12:10 -0700
                    Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-08 20:41 +0100
                      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-09 09:55 -0700
                        Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-09 11:18 -0700
                          Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-09 19:25 +0100
                            Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-09 13:49 -0700
                              Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-09 22:09 +0100
        Re: Fun/Funny Fractal Encryption... Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-07-08 00:49 -0700
    Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-07 23:05 -0700
      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-07 23:15 -0700
    Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-10 12:25 -0700
      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-10 15:09 -0700
      Re: Fun/Funny Fractal Encryption... Richard Heathfield <rjh@cpax.org.uk> - 2015-07-15 15:52 +0100
      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-31 13:40 -0700
        Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-31 13:43 -0700
          Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-31 13:46 -0700
        Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-08-21 14:45 -0700
          Re: Fun/Funny Fractal Encryption... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-22 01:29 +0100
            Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-08-21 20:03 -0700
              Re: Fun/Funny Fractal Encryption... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-22 13:02 +0100
                Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-08-22 18:15 -0700
      Re: Fun/Funny Fractal Encryption... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-08-16 12:10 -0700
        Re: Fun/Funny Fractal Encryption... luser droog <luser.droog@gmail.com> - 2015-08-22 22:49 -0700

Page 2 of 2 — ← Prev page 1 [2]


#65180

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-07-10 12:25 -0700
Message-ID<mnp683$pld$1@speranza.aioe.org>
In reply to#64884
> "Chris M. Thomasson"  wrote in message 
> news:mnhpm5$fh9$1@speranza.aioe.org... [...]

This is cross-posted with comp.lang.c. I am hoping some of them take a look 
at the C
program and perhaps find some bugs for me to fix!  :^)

Anyway...
____________________________________________________

I have created a pre-alpha version of a fun little toy
project I call “Funny Fractal Encryption”. It is based
on the idea of generating a stream cypher out of renderings
from fractal formulas. The initial version of the program
is using escape time fractals, Julia set in this case. The
escape iteration counts mutated with color transformation
functions and an orbit trap are then used to build a cypher
of a given location in the fractal. This cypher is then
used to encrypt the cleartext using simple modular arithmetic.
I can get a fairly decent avalanche effect of the resulting
cypertext by using the contents of the cleartext to decide
on what location to go in the Julia set. This location is
used as a public key that can be sent across the wire along
with its associated cypertext. The private key would consist
of a fractal formula, a location in the complex plane and an
iteration count. The resulting cypertext is VERY sensitive
to very small mutations in the fractal settings.

So, the overall scheme for this type of encryption would be
something like:

Bob and Alice want to send/receive encrypted messages to/from
each other.

Bob and Alice decide on a private key K0 consisting of a fractal
formula, location and iteration count that ends up rendering a
beautiful image.

Bob wants to send a message M to Alice, so he uses M to generate
a private key K1 consisting of a location. He then uses K0 and
K1 to generate a new fractal F. Bob then uses F to encrypt M as
EM.

Bob sends EM and K1 across the wire to Alice.

Alice uses the keys K0 and K1 to gain the fractal F.

Alice uses F to decrypt EM back into M.

Alice reads M.


Here is the C code for an embryonic version, pre-alpha indeed!
;^)

http://pastebin.com/fcV5YiJH
(this is the most recent version of the code)

I am VERY interested in any cyrpto analysis that can crack the
formula/key responsible for encrypting several messages with
the same public key/derived-fractal. Keep in mind that the derived
fractal, or public key should be mathematically tied to the original
private fractal.

FWIW, here is a link to the original thread I started over in
comp.lang.c:

https://groups.google.com/d/topic/comp.lang.c/vui6XP-IxRM/discussion
(this link has links to older versions of the program on pastebin)


Well, is this 100% crap, or “perhaps” not all that shi%Ty?

;^o 

[toc] | [prev] | [next] | [standalone]


#65197

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-07-10 15:09 -0700
Message-ID<mnpfs1$g4m$1@speranza.aioe.org>
In reply to#65180
> > "Chris M. Thomasson"  wrote in message 
> > news:mnp683$pld$1@speranza.aioe.org...

> > "Chris M. Thomasson"  wrote in message 
> > news:mnhpm5$fh9$1@speranza.aioe.org... [...]

> I am VERY interested in any cyrpto analysis that can crack the
> formula/key responsible for encrypting several messages with
> the same public key/derived-fractal. Keep in mind that the derived
> fractal, or public key should be mathematically tied to the original
> private fractal.

Yikes! I made a typo in there.

The public key is generated from the cleartext and is
tied to the ciphertext via the private key and can be
sent across the wire as is.

So, I would like to see the private key cracked out of
a series of ciphertexts and their associated public keys.

For instance, here are mutations to the phrase "Hello World"
encrypted with the program as-is. Keep in mind that you
know the private key, and the public keys. So, how you
one go about cracking another key that happens to works
for all of the following cipher texts:


public key = 0.068879
original   = Hello World
encrypted  = d*GCXsUFHG`
decrypted  = Hello World


public key = 0.235041
original   = hello World
encrypted  = FF!]y@prMak
decrypted  = hello World


public key = 0.224501
original   = Hello Wordl
encrypted  = F2MNVaqXhve
decrypted  = Hello Wordl


public key = 0.059056
original   = Hello World Hello
encrypted  = 1zCCZlG?'%e7pAfk7
decrypted  = Hello World Hello


public key = 0.107481
original   = Hello World hello
encrypted  = %')Ln2,(Pf>IA sq5
decrypted  = Hello World hello



Is there an obvious pattern I totally missing!

;^/

[toc] | [prev] | [next] | [standalone]


#65623

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-07-15 15:52 +0100
Message-ID<mo5s0m$um6$1@dont-email.me>
In reply to#65180
[Followups set to sci.crypt]

On 10/07/15 20:25, Chris M. Thomasson wrote:

<snip>

> I am VERY interested in any cyrpto analysis that can crack the
> formula/key responsible for encrypting several messages with
> the same public key/derived-fractal. Keep in mind that the derived
> fractal, or public key should be mathematically tied to the original
> private fractal.

Chris, the first step is to try to crack the algorithm yourself.

That doesn't necessarily mean recovering a plaintext from a ciphertext 
(without the key). Here are some ways to illustrate that a cipher is 
insecure (not all will necessarily apply to every cipher, but most will 
apply to most):

1) A frequency analysis shows that the distribution of ciphertext 
characters varies significantly from what you would expect from 
randomly-generated data. This is a relatively easy task. 
(Transposition-only ciphers are bound to fail this test, which doesn't 
necessarily mean they're no use.)

2) A change of a single bit in the plaintext results in a trifling 
change in the ciphertext. One would expect, in a strong cipher, that the 
alteration of a single bit in the plaintext would result in roughly half 
the bits of the ciphertext changing (and these changes would be 
distributed apparently at random through the file).

3) The cipher falls to the usual attacks on monoalphabetic or 
polyalphabetic substitution ciphers. (Look up "Kasiski" and/or "Index of 
Coincidence".)

4) Given a known plaintext (i.e. you have the ciphertext and you know at 
least some of the plaintext that generated it), you can recover the key.

Those might be considered the most basic attacks. You need to try these 
for yourself. You will never design a first-class (or even second- or 
third-class) cipher if you don't acquire some experience in breaking 
ciphers. (And it's quite a diverting exercise in its own right.)

When you ask "can anyone break this?", they're much more likely to *try* 
if you can say "the ciphertext is indistinguishable from random, the 
avalanching is up to snuff, and I tried the foo, bar, and baz attacks, 
but couldn't make any headway" - in other words, if you've eliminated 
the obvious and also shown that you've made an effort.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#66619

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-07-31 13:40 -0700
Message-ID<mpgmfd$q02$1@speranza.aioe.org>
In reply to#65180
FWIW, here is the latest version that can encrypt any file:

http://pastebin.com/rQRXU5Mb

The command line for encryption is:

<flag> = 0 means encrypt
<flag> = 1 means decrypt

<program> <cleartext.file[in]> <ciphertext.file[out]> <flag:0> <xmin> <xmax> 
<ymin> <ymax>


The command like for decryption is:

<program> <ciphertext.file[in]> <cleartext.file[out]> <flag:1> <xmin> <xmax> 
<ymin> <ymax>


Running the program in encrypt mode gives a command line that
can decrypt the generated ciphertext. Here is output I get for
the same file I posted the freqency distributions for in the
ShuttlePads thread:
____________________________________________________________________
xmin = -0.50000000000
xmax = 0.50000000000
ymin = -0.50000000000
ymax = 0.50000000000
Opened the cleartext [in]! <C:\Users\Chris\Desktop\cleartext.txt>
Opened the ciphertext [out]! <C:\Users\Chris\Desktop\ciphertext.txt>
ffe_encrypt_first_pass processed: 703149 bytes

lost precision: 0.0000000000006
lost precision: 0.0000000000035
lost precision: 0.0000000000039
lost precision: 0.0000000000050
pub_xmin_scale = -0.39747846419
pub_xmax_scale = 1.22504427779
pub_ymin_scale = -0.37951654765
pub_ymax_scale = 0.67335246548

file size: 703149
fractal dims: 840 x 840

Passed at 703149 bytes!



Decrypt Command Line:

C:\Users\Chris\Desktop\ciphertext.txt 
C:\Users\Chris\Desktop\cleartext.txt_dc 1
-0.39747846419 1.22504427779 -0.37951654765 0.67335246548


No Errors Reported!

Closed the ciphertext [out]! <C:\Users\Chris\Desktop\ciphertext.txt>
Closed the cleartext [in]! <C:\Users\Chris\Desktop\cleartext.txt>

Complete!


The decrypt command line is:

C:\Users\Chris\Desktop\ciphertext.txt 
C:\Users\Chris\Desktop\cleartext.txt_dc 1 -0.39747846419 
1.22504427779 -0.37951654765 0.67335246548


This code is in a fairly sad state. Its in flux. I need to check
sscanf for errors damn it!

But, at least you can see how this works and can make your own
analysis of the ciphertexts for any file.


Also, keep in mind that the private key is hard coded into the
program as:

{ -0.7, 0.25 }

So, every ciphertext will be based off a location into this
paticiular Julia set. I need to make the program able to allow
a user to provide their own actual formula and locations, iteration
counts, color monitors, ect... Lot of work to do!

Yikes!

;^o

[toc] | [prev] | [next] | [standalone]


#66620

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-07-31 13:43 -0700
Message-ID<mpgmlq$q88$1@speranza.aioe.org>
In reply to#66619
> "Chris M. Thomasson"  wrote in message 
> news:mpgmfd$q02$1@speranza.aioe.org...

> FWIW, here is the latest version that can encrypt any file:

> http://pastebin.com/rQRXU5Mb

Ummmm.... There is a damn getchar that I forgot to remove! So, the program
completes and hits a damn getchar. Well, you need to hit a key. Anyway,
I forgot to remove this. Sorry!!!!

;^o


Here is the code just in case PasteBin does not work for some reason:

(this one has the getchar commented out)
__________________________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>



/*-------------------------*/
#define CT_LB "\r\n"
#define CT_PREC "%.11lf"
#define CT_PREC_EPS "%.13lf"
#define CT_EPS 0.00000000001
#define CT_MIN(mp_0, mp_1) ((mp_0) < (mp_1) ? (mp_0) : (mp_1))

struct main_args
{
    int argc;
    char** argv;
};





/*-------------------------*/
double
double_to_string_to_double(
    double n
){
    double nn = 0.0;
    double ndif = 0.0;

    char nbuf[UCHAR_MAX + 1] = { '\0' };

    sprintf(nbuf, CT_PREC, n);

    sscanf(nbuf, "%lf", &nn);

    ndif = fabs(n - nn);

    /* `nn' has lost precision of `n'.*/
    printf("lost precision: " CT_PREC_EPS CT_LB, ndif);

    return nn;
}


double
string_to_double(
    char const* nbuf
){
    double n = 0.0;

    sscanf(nbuf, "%lf", &n);

    return n;
}


unsigned int
string_to_uint(
    char const* nbuf
){
    unsigned int n = 0;

    sscanf(nbuf, "%u", &n);

    return n;
}





/*-------------------------*/
#define SQ(mp_0) ((mp_0)*(mp_0))


struct complexn
{
    double x;
    double y;
};


#define COMPLEXN_SINIT() { 0.0, 0.0 }


struct complexn
complexn_add(
    struct complexn self,
    struct complexn n
){
    struct complexn p = {
        self.x + n.x,
        self.y + n.y
    };

    return p;
}


struct complexn
complexn_mul(
    struct complexn self,
    struct complexn n
){
    struct complexn p = {
        self.x * n.x - self.y * n.y,
        self.x * n.y + self.y * n.x
    };

    return p;
}




/*--------------------------*/
unsigned long
cantor_packing(
    unsigned int n0,
    unsigned int n1
){
    unsigned long ret = 0.5 * (n0 + n1) * (n0 + n1 + 1) + n1;

    return ret;
}





/*-------------------------*/
#define FFE_MARGS_NMIN 7
#define FFE_BUF_NMAX (1024 * 756)
#define FFE_ABETN (UCHAR_MAX + 1U)


struct ffe_buf
{
    unsigned char buf[FFE_BUF_NMAX];
    size_t bufsz;
};


struct ffe_abet
{
    unsigned int abet[UCHAR_MAX + 1];
};


struct ffe_cplane
{
    double xmin;
    double xmax;
    double ymin;
    double ymax;
};

unsigned int
ffe_cplane_iterate(
    struct complexn c,
    struct complexn j,
    unsigned int imax
){
    unsigned int i = 0;
    unsigned int imod = 0;

    double dmin = 999999999999.0;

    struct complexn z = c;
    c = j; /* Julia Mode */

    for (i = 0; i < imax; ++i)
    {
        double zd = 0.0;

        z = complexn_mul(z, z);
        z = complexn_add(z, c);

        zd = SQ(z.x) + SQ(z.y);

        dmin = CT_MIN(dmin, zd);

        if (zd > 4.0)
        {
            imod = (unsigned int)((20371 + i) *
                fabs(cos(i * i * dmin * 252307))) % FFE_ABETN;

            return imod;
        }
    }

    imod = (unsigned int)(40377 *
        fabs(sin(dmin * 152307))) % FFE_ABETN;

    return imod;
}




size_t
ffe_buf_read(
    struct ffe_buf* const self,
    FILE* const file
){
    self->bufsz = fread(self->buf, 1, FFE_BUF_NMAX, file);

    if (self->bufsz == FFE_BUF_NMAX)
    {
        return self->bufsz;
    }

    if (! ferror(file))
    {
        if (feof(file))
        {
            return self->bufsz;
        }
    }

    printf("fread error!" CT_LB);

    return 0;
}


size_t
ffe_buf_write(
    struct ffe_buf const* const self,
    FILE* const file
){
    size_t bufsz = fwrite(self->buf, 1, self->bufsz, file);

    if (bufsz == FFE_BUF_NMAX)
    {
        return bufsz;
    }

    if (! ferror(file))
    {
        return bufsz;
    }

    printf("fwrite error!" CT_LB);

    return 0;
}





/*-------------------------*/

struct ffe_encrypt
{
    struct ffe_cplane cplane;      /* private key: plane */
    struct complexn jplane;        /* private key: Julia */
    struct ffe_cplane pub_cplane;  /* public key: plane */

    struct ffe_buf* ebuf;
    unsigned int flags;
    size_t uwidth;
    size_t fbytes;

    FILE* fctext;  /* clear text file */
    FILE* fcipher; /* cipher text file */
};


int
ffe_encrypt_main_args_fctext_parse(
    struct ffe_encrypt* const self,
    struct main_args* const margs
){
    if (margs->argc == FFE_MARGS_NMIN + 1)
    {
        unsigned int base = 1;

        /* Try to open the cleartext [in] */
        self->fctext = fopen(margs->argv[base], "rb");

        if (self->fctext)
        {
            printf("Opened the cleartext [in]! <%s>" CT_LB, margs->argv[1]);

            /* Try to open the ciphertext [out] */
            self->fcipher = fopen(margs->argv[base + 1], "wb");

            if (self->fcipher)
            {
                printf("Opened the ciphertext [out]! <%s>" CT_LB, 
margs->argv[base + 1]);

                return 1;
            }

            else
            {
                printf("Cannot open the ciphertext [out]! <%s>" CT_LB, 
margs->argv[base + 1]);
            }

            fclose(self->fctext); /* check for errors!?!? */
        }

        printf("Cannot open the cleartext [int]! <%s>" CT_LB, 
margs->argv[base]);
    }

    return 0;
}


int
ffe_encrypt_main_args_cplane_parse(
    struct ffe_encrypt* const self,
    struct main_args* const margs
){
    if (margs->argc == FFE_MARGS_NMIN + 1)
    {
        /* Parse the complex plane dimensions (2d for now) */
        unsigned int const icpbase = 3;

        self->flags = string_to_uint(margs->argv[icpbase + 0]);

        self->cplane.xmin = string_to_double(margs->argv[icpbase + 1]);
        self->cplane.xmax = string_to_double(margs->argv[icpbase + 2]);

        self->cplane.ymin = string_to_double(margs->argv[icpbase + 3]);
        self->cplane.ymax = string_to_double(margs->argv[icpbase + 4]);

        return 1;
    }

    return 0;
}


int
ffe_encrypt_parse(
    struct ffe_encrypt* const self,
    struct main_args* const margs
){
    if (ffe_encrypt_main_args_cplane_parse(self, margs))
    {
        printf(
            "xmin = " CT_PREC CT_LB "xmax = " CT_PREC CT_LB
            "ymin = " CT_PREC CT_LB "ymax = " CT_PREC CT_LB,
            self->cplane.xmin, self->cplane.xmax,
            self->cplane.ymin, self->cplane.ymax
        );

        if (ffe_encrypt_main_args_fctext_parse(self, margs))
        {
            return 1;
        }
    }

    return 0;
}


void
ffe_encrypt_first_pass(
    struct ffe_encrypt* const self,
    struct main_args const* const margs
){
    self->fbytes = 0;
    double cmean_sum = 0.0;
    size_t cpack_msum = 0;
    size_t cxor = 0;

    for (;;)
    {
        size_t rbytes = ffe_buf_read(self->ebuf, self->fctext);

        if (rbytes != 0)
        {
            size_t i = 0;

            for (i = 0; i < rbytes; i += 2)
            {
                double cavg_0 = self->ebuf->buf[i] / ((double)UCHAR_MAX);
                double cavg_1 = self->ebuf->buf[i + 1] / 
((double)UCHAR_MAX);

                cmean_sum = cmean_sum + cavg_0 + cavg_1;

                cpack_msum =
                    (cpack_msum + cantor_packing(
                    self->ebuf->buf[i], self->ebuf->buf[i + 1])) % 
1073741823;

                cxor = cxor ^ self->ebuf->buf[i];
                cxor = cxor ^ self->ebuf->buf[i + 1];
                cxor = cxor ^ cpack_msum;

                cmean_sum += ((cxor) % (UCHAR_MAX)) / ((double)UCHAR_MAX);
            }

            printf("ffe_encrypt_first_pass processed: %lu bytes" CT_LB, 
(unsigned long)rbytes);

            self->fbytes = self->fbytes + rbytes;

            continue;
        }

        break;
    }

    printf(CT_LB);

    {
        /* build new location/offset (Public Key) into (Private Key) */
        double cavg = cmean_sum / ((double)self->fbytes);
        double cfmod = ((cavg + (cpack_msum / cxor)) * cxor) / ((cxor + 
cpack_msum) % 1237);
        cfmod = fmod(cfmod, 1.0);

        /* try to avoid divide-by-zero conditions */
        if (! cxor) cxor = 1;
        if (! cpack_msum) cpack_msum = 1;

        {
            /* Generate Public Key Scale */
            unsigned int sum_mod = 5;
            double fmod_scale = ((1.0 + sqrt(5.0)) / 2.0) / 2.0;
            double pub_xmin_scale = fmod(cavg * cfmod + (cxor / 
(double)cpack_msum), fmod_scale);
            double pub_xmax_scale = fmod((cavg * cfmod) * cxor + (cxor / 
(double)cpack_msum), fmod_scale);
            double pub_ymin_scale = fmod(cavg + cfmod + (cxor / 
(double)cpack_msum), fmod_scale);
            double pub_ymax_scale = fmod((cavg + cfmod) * cxor + (cxor / 
(double)cpack_msum), fmod_scale);

            pub_xmin_scale = pub_xmin_scale / ((cxor % 7) + 3);
            pub_xmax_scale = pub_xmax_scale / (((cxor + cpack_msum) % 7) + 
1);
            pub_ymin_scale = pub_ymin_scale / (((cxor * cpack_msum) % 7) + 
1);
            pub_ymax_scale = pub_ymax_scale / (((((cxor * 3 + cpack_msum) + 
7)) % 7) + 1);

            pub_xmin_scale = (fmod(pub_xmin_scale + (cavg / 7), fmod_scale)) 
+ self->cplane.xmin;
            pub_xmax_scale = (fmod(pub_xmax_scale + (cavg / 7), fmod_scale)) 
+ self->cplane.xmax;
            pub_ymin_scale = (fmod(pub_ymin_scale + (cavg / 7), fmod_scale)) 
+ self->cplane.ymin;
            pub_ymax_scale = (fmod(pub_ymax_scale + (cavg / 7), fmod_scale)) 
+ self->cplane.ymax;

            cavg = fmod(cavg, fmod_scale);
            cfmod = fmod(cfmod, fmod_scale);
            cavg = 1.0 - fmod(cavg + cfmod, fmod_scale);

            cpack_msum = cpack_msum * cavg + (cpack_msum % sum_mod) + 1;
            cxor = cxor + (cxor % sum_mod) + 1;


            self->pub_cplane.xmin = 
double_to_string_to_double(pub_xmin_scale);
            self->pub_cplane.xmax = 
double_to_string_to_double(pub_xmax_scale);
            self->pub_cplane.ymin = 
double_to_string_to_double(pub_ymin_scale);
            self->pub_cplane.ymax = 
double_to_string_to_double(pub_ymax_scale);


            /* decrypt setting 0 */
            if (self->flags == 1)
            {
                self->pub_cplane = self->cplane;
            }


            printf("pub_xmin_scale = " CT_PREC CT_LB, 
self->pub_cplane.xmin);
            printf("pub_xmax_scale = " CT_PREC CT_LB, 
self->pub_cplane.xmax);
            printf("pub_ymin_scale = " CT_PREC CT_LB, 
self->pub_cplane.ymin);
            printf("pub_ymax_scale = " CT_PREC CT_LB, 
self->pub_cplane.ymax);
        }
    }
}


int
ffe_encrypt_second_pass(
    struct ffe_encrypt* const self,
    struct main_args const* const margs
){
    double xwidth = self->pub_cplane.xmax - self->pub_cplane.xmin;
    double xheight = self->pub_cplane.ymax - self->pub_cplane.ymin;

    double xstep = xwidth / self->uwidth;
    double ystep = xheight / self->uwidth;

    struct complexn c = COMPLEXN_SINIT();

    {
        size_t i = 0;

        rewind(self->fctext);

        printf(CT_LB);

        for (i = 0; i < self->fbytes;)
        {
            size_t rbytes = ffe_buf_read(self->ebuf, self->fctext);

            if (rbytes != 0)
            {
                size_t ic = 0;

                for (ic = 0; ic < rbytes; ++ic, ++i)
                {
                    /* Apply the cipher */
                    unsigned int imod = 0;
                    unsigned int cmod = self->ebuf->buf[ic];

                    unsigned int yi = i / self->uwidth;
                    unsigned int xi = i - yi * self->uwidth;

                    c.x = self->pub_cplane.xmin + xi * xstep;
                    c.y = self->pub_cplane.ymin + yi * ystep;

                    imod = ffe_cplane_iterate(c, self->jplane, 503);



                    /* encrypt/decrypt */
                    if (self->flags == 0)
                    {
                        imod = (imod + cmod) % FFE_ABETN;
                    }

                    else
                    {
                        int ec = cmod - imod;

                        if (ec < 0)
                        {
                            ec = cmod + FFE_ABETN;
                            imod = abs(imod - ec);
                        }

                        else
                        {
                            imod = ec;
                        }
                    }

                    /* commit cipher char to buffer */
                    self->ebuf->buf[ic] = imod;

                    if (! (i % 1000))
                    {
                        printf("i = %lu\r", (unsigned long)i);
                    }
                }

                /* write buffer to cipher file */
                {
                    size_t wbytes = ffe_buf_write(self->ebuf, 
self->fcipher);

                    if (wbytes < rbytes)
                    {
                        /* need to loop until the buffer is commited! */
                        printf("SINGLE WRITE IS FUC%%ED!" CT_LB);
                        getchar();
                    }
                }

                continue;
            }

            break;
        }

        if (i == self->fbytes)
        {
            printf("Passed at %lu bytes!" CT_LB CT_LB, (unsigned long)i);

            return 1;
        }
    }

    return 0;
}




/*-------------------------*/
int
main(
    int argc,
    char* argv[]
){
    struct main_args self = { argc, argv };

    {
        struct ffe_buf ebuf = { { '\0' } };

        struct ffe_encrypt fenc = {
            { -2.0, 2.0, -2.0, 2.0, },      /* private key: plane */

            /* need to put this in the cmd line damn it! */
            { -0.7, 0.25 },                 /* private key: Julia */

            { 0.0, 0.0, 0.0, 0.0, },        /* public key */
            &ebuf,
            0,
            0,
            0,
            NULL,
            NULL
        };

        if (ffe_encrypt_parse(&fenc, &self))
        {
            ffe_encrypt_first_pass(&fenc, &self);

            printf(CT_LB);
            printf("file size: %lu" CT_LB, (unsigned long)fenc.fbytes);

            /* gain dims of fractal pad */
            fenc.uwidth = (sqrt(fenc.fbytes) + 1.681) * 1.0;

            printf("fractal dims: %lu x %lu" CT_LB,
                (unsigned long)fenc.uwidth,
                (unsigned long)fenc.uwidth
            );

            if (ffe_encrypt_second_pass(&fenc, &self))
            {
                if (fenc.flags == 0)
                {
                    unsigned int base = 1;

                    printf(CT_LB CT_LB "Decrypt Command Line:" CT_LB CT_LB);
                    printf("%s %s_dc 1 " CT_PREC " " CT_PREC " " CT_PREC " " 
CT_PREC CT_LB CT_LB,
                        self.argv[base + 1],
                        self.argv[base],
                        fenc.pub_cplane.xmin,
                        fenc.pub_cplane.xmax,
                        fenc.pub_cplane.ymin,
                        fenc.pub_cplane.ymax);
                }

                printf(CT_LB "No Errors Reported!" CT_LB CT_LB);
            }

            /* Check for ERRORS! */
            fclose(fenc.fcipher);
            printf("Closed the ciphertext [out]! <%s>" CT_LB, self.argv[2]);

            fclose(fenc.fctext);
            printf("Closed the cleartext [in]! <%s>" CT_LB, self.argv[1]);
        }

        else
        {
            printf("failed to parse!" CT_LB);
        }
    }

    puts(CT_LB "Complete!" CT_LB);
    /* getchar(); */

    return 0;
}
__________________________________________________________________

[toc] | [prev] | [next] | [standalone]


#66621

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-07-31 13:46 -0700
Message-ID<mpgmrl$qpl$1@speranza.aioe.org>
In reply to#66620
One more thing... I am creating a single buffer on the stack the size of 
`FFE_BUF_NMAX':
_________________________________________________
#define FFE_MARGS_NMIN 7
#define FFE_BUF_NMAX (1024 * 756)
#define FFE_ABETN (UCHAR_MAX + 1U)
_________________________________________________


This might be too much for your stack. So, if you get a stack overflow, 
well, make
`FFE_BUF_NMAX'' smaller!


:^O 

[toc] | [prev] | [next] | [standalone]


#67968

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-08-21 14:45 -0700
Message-ID<mr867b$o02$1@speranza.aioe.org>
In reply to#66619
> "Chris M. Thomasson"  wrote in message 
> news:mpgmfd$q02$1@speranza.aioe.org...

> FWIW, here is the latest version that can encrypt any file:

> http://pastebin.com/rQRXU5Mb

Quick question: Has anybody tried to compile this?

If so, how did it go?

:^o 

[toc] | [prev] | [next] | [standalone]


#67972

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-08-22 01:29 +0100
Message-ID<8737zc88t8.fsf@bsb.me.uk>
In reply to#67968
"Chris M. Thomasson" <nospam@nospam.nospam> writes:

>> "Chris M. Thomasson"  wrote in message
>> news:mpgmfd$q02$1@speranza.aioe.org...
>
>> FWIW, here is the latest version that can encrypt any file:
>
>> http://pastebin.com/rQRXU5Mb
>
> Quick question: Has anybody tried to compile this?

No, but I did just now since you asked...

> If so, how did it go?

Not bad.  A lot of conversion warnings (I use -Wconversion on all new
code just to get the lie of the land) but they may well be fine.

A warning about unused parameter (margs) and one about a missing
initialiser for bufsz in struct ffe_buf.  Only that last one worried me.

Running the result says

  failed to parse!

  Complete!

which indicates something is wrong.  Do I need some hardware-specific
flags?  This is gcc version 4.9.2 on an i7-3520M CPU.

You are avoiding C's complex type but using some other C99 features.
That's not wrong, but a little odd.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#67974

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-08-21 20:03 -0700
Message-ID<mr8oqi$re1$1@speranza.aioe.org>
In reply to#67972
> "Ben Bacarisse"  wrote in message news:8737zc88t8.fsf@bsb.me.uk...

>>  "Chris M. Thomasson" <nospam@nospam.nospam> writes:

> >> "Chris M. Thomasson"  wrote in message
> >> news:mpgmfd$q02$1@speranza.aioe.org...
> >
> >> FWIW, here is the latest version that can encrypt any file:
> >
> >> http://pastebin.com/rQRXU5Mb
>
> > > Quick question: Has anybody tried to compile this?

> No, but I did just now since you asked...

> > If so, how did it go?

> Not bad.  A lot of conversion warnings (I use -Wconversion on all new
> code just to get the lie of the land) but they may well be fine.

I think they are okay.


> A warning about unused parameter (margs) and one about a missing
> initialiser for bufsz in struct ffe_buf.  Only that last one worried me.

I am not seeing those warnings. The unused parameter (margs)
almost has to be in the (ffe_encrypt_first_pass) and
(ffe_encrypt_second_pass) functions. As for the last one, well
could you please provide me with a line number? I am compiling
this with with Mingw 4.9.2 and the most recent MSVC. Unfortunately,
none of them give these warnings Ben!

Damn.



> Running the result says

>   failed to parse!

>   Complete!

> which indicates something is wrong.  Do I need some hardware-specific
> flags?  This is gcc version 4.9.2 on an i7-3520M CPU.

It will output “Complete!” regardless of how it exits, and this is
a flaw. The failed to parse error means that it did not get enough
command line arguments; it requires 7 of them. The command line syntax
for this is:



<flag> = 0 means encrypt

<flag> = 1 means decrypt



<program> <cleartext.file[in]> <ciphertext.file[out]> <flag:0>
<xmin> <xmax>
<ymin> <ymax>





The command like for decryption is:



<program> <ciphertext.file[in]> <cleartext.file[out]> <flag:1>
<xmin> <xmax>
<ymin> <ymax>




Running the program in encrypt mode gives a command line that
can decrypt the generated ciphertext.




Example for encryption:



ffe C:\plaintext.txt C:\ciphertext.dat 0 -0.5 0.5 -0.5 0.5



Does something like that work? FWIW, here is the command line
I am using in my test environment over on Windows 7:




ffe C:\Users\Chris\Desktop\ffe_dat\cleartext.txt
C:\Users\Chris\Desktop\ffe_dat\ciphertext.txt 0 -0.5 0.5 -0.5 0.5


The <xmin> <xmax> <ymin> <ymax> arguments define the 2d plane/
location in which the fractal will be processed.



> You are avoiding C's complex type but using some other C99 features.
> That's not wrong, but a little odd.

Yeah, I just could not get the standard built in complex type to
work for me for some reason.

Damn again.

;^o



Can you try creating a simple text file, called plaintext.txt,
and running the program with:

ffe <path_to_plaintext.txt> <path_to_ciphertext.dat> 0
-0.5 0.5 -0.5 0.5

something like:

ffe plaintext.txt ciphertext.dat 0 -0.5 0.5 -0.5 0.5

This will read the plaintext.txt file and create a new file
called ciphertext.dat. The program will the output a command
line that can be used to decrypt the ciphertext.dat.

Again, I am sorry for the sorry state of the crude, embryonic
version of the code!

;^o 

[toc] | [prev] | [next] | [standalone]


#68001

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-08-22 13:02 +0100
Message-ID<87wpwn7cpj.fsf@bsb.me.uk>
In reply to#67974
"Chris M. Thomasson" <nospam@nospam.nospam> writes:

>> "Ben Bacarisse"  wrote in message news:8737zc88t8.fsf@bsb.me.uk...
>
>>>  "Chris M. Thomasson" <nospam@nospam.nospam> writes:
>
>> >> "Chris M. Thomasson"  wrote in message
>> >> news:mpgmfd$q02$1@speranza.aioe.org...
>> >
>> >> FWIW, here is the latest version that can encrypt any file:
>> >
>> >> http://pastebin.com/rQRXU5Mb
>>
>> > > Quick question: Has anybody tried to compile this?
>
>> No, but I did just now since you asked...
>
>> > If so, how did it go?
>
>> Not bad.  A lot of conversion warnings (I use -Wconversion on all new
>> code just to get the lie of the land) but they may well be fine.
>
> I think they are okay.
>
>
>> A warning about unused parameter (margs) and one about a missing
>> initialiser for bufsz in struct ffe_buf.  Only that last one worried me.
>
> I am not seeing those warnings. The unused parameter (margs)
> almost has to be in the (ffe_encrypt_first_pass) and
> (ffe_encrypt_second_pass) functions. As for the last one, well
> could you please provide me with a line number?

Line 588.  I'd add a 0 just to clear it up:

  struct ffe_buf ebuf = { { '\0' }, 0 };

In fact, I might write it

  struct ffe_buf ebuf = { "", 0 };

but that's hardly important.

<snip>
>> Running the result says
>
>>   failed to parse!
>
>>   Complete!
>
>> which indicates something is wrong.  Do I need some hardware-specific
>> flags?  This is gcc version 4.9.2 on an i7-3520M CPU.
>
> It will output “Complete!” regardless of how it exits, and this is
> a flaw. The failed to parse error means that it did not get enough
> command line arguments; it requires 7 of them.
<snip>

> Example for encryption:
>
> ffe C:\plaintext.txt C:\ciphertext.dat 0 -0.5 0.5 -0.5 0.5
>
> Does something like that work?

Yes.  I can do an encrypt/decrypt cycle fine.

The program's a bit wordy but that's probably a Windows/Unix culture
clash.

<snip>
> Again, I am sorry for the sorry state of the crude, embryonic
> version of the code!

It's fine, but a one-line "usage" message would have enabled me to test
it right away.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#68078

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-08-22 18:15 -0700
Message-ID<mrb6rr$3bf$1@speranza.aioe.org>
In reply to#68001
> "Ben Bacarisse"  wrote in message news:87wpwn7cpj.fsf@bsb.me.uk...
[...]
> > "Chris M. Thomasson" <nospam@nospam.nospam> writes:
[...]
> >> "Ben Bacarisse"  wrote in message news:8737zc88t8.fsf@bsb.me.uk...
[...]
> >> A warning about unused parameter (margs) and one about a missing
> >> initialiser for bufsz in struct ffe_buf.  Only that last one worried 
> >> me.
> >
> > I am not seeing those warnings. The unused parameter (margs)
> > almost has to be in the (ffe_encrypt_first_pass) and
> > (ffe_encrypt_second_pass) functions. As for the last one, well
> > could you please provide me with a line number?

> Line 588.  I'd add a 0 just to clear it up:

>   struct ffe_buf ebuf = { { '\0' }, 0 };

> In fact, I might write it

>   struct ffe_buf ebuf = { "", 0 };

> but that's hardly important.


Thank you for helping me spot this. Also, I am very happy that
the pre-alpha code seems to be working for you.

Thanks again Ben.

:^D

[toc] | [prev] | [next] | [standalone]


#67539

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-08-16 12:10 -0700
Message-ID<mqqn7m$35i$1@speranza.aioe.org>
In reply to#65180
> "Chris M. Thomasson"  wrote in message 
> news:mnp683$pld$1@speranza.aioe.org...

> > "Chris M. Thomasson"  wrote in message 
> > news:mnhpm5$fh9$1@speranza.aioe.org... [...]

> This is cross-posted with comp.lang.c. I am hoping some of them take a 
> look at the C program and perhaps find some bugs for me to fix!  :^)

I am going to code my cryptoalgorithm in Javascript and put it up on a 
website.

Then one will not have to compile the C code in order to play around with 
the toy!

;^) 

[toc] | [prev] | [next] | [standalone]


#68092

Fromluser droog <luser.droog@gmail.com>
Date2015-08-22 22:49 -0700
Message-ID<f160c6f6-61b1-40da-914b-cc6440875388@googlegroups.com>
In reply to#67539
On Sunday, August 16, 2015 at 2:11:04 PM UTC-5, Chris M. Thomasson wrote:
> > "Chris M. Thomasson"  wrote in message 
> > news:mnp683$pld$1@speranza.aioe.org...
> 
> > > "Chris M. Thomasson"  wrote in message 
> > > news:mnhpm5$fh9$1@speranza.aioe.org... [...]
> 
> > This is cross-posted with comp.lang.c. I am hoping some of them take a 
> > look at the C program and perhaps find some bugs for me to fix!  :^)
> 
> I am going to code my cryptoalgorithm in Javascript and put it up on a 
> website.
> 
> Then one will not have to compile the C code in order to play around with 
> the toy!
> 
> ;^)

Have you heard of Emscripten? You can compile to javscript.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web