# Re: how shd i improve upon this algorithm(ne suggestions)

From: John Savard (jsavard_at_excxn.aNOSPAMb.cdn.invalid)
Date: 07/16/04

```Date: Fri, 16 Jul 2004 15:45:44 GMT

```

I think I understand what you are talking about here.

Step 1: Encipher the input bytes by means of a simple substitution of
values from 0 to 255.

Step 2: Split the result bytes into two four bit halves.

Step 3: Add four random bits to each half.

This can be improved. Right now, what you are producing is a
homophonic cipher with 16 substitutes for each half of the byte.

One way to vary things more is this:

Instead of replacing each four bits by itself and four random bits,
choose two groups of four bits that add together to, or XOR together
to, the original four bits.

And don't forget an extra substitution step at the end.

One could also put them together in a straddling fashion, to avoid
having pairs of characters that have 256 values for every byte.

Thus:

01011100 11011010

becomes

11011001 00110100

by substitution...

1101 can become 0110 and 1011
1001 can become 1100 and 0101
0011 can become 1011 and 1000
0100 can become 1010 and 1110

and so on...

and what we do is for the first nibble, take the two nibbles and put
them in the preceding in-between byte and the matching byte, but for
the second byte, put them in the matching byte and the following
in-between byte:

01011100 11011010
11011001 00110100
0110.... 10111100 10110101 10001010 ....1110

and then substitute.

This still won't be all that secure, though. But at least, no matter
what the plaintext is, any given byte in the ciphertext can be any of
the 256 possibilities.

John Savard
http://home.ecn.ab.ca/~jsavard/index.html

## Relevant Pages

• Re: performance surprise -- why?
... On 25 Aug 2004, Anno Siegel wrote: ... >> string to a file and counted the lengths of the lines using a simple ... The substitution method must move parts of the ... > The results show indexing and global matching in the same ballpark, ...
(comp.lang.perl.misc)
• Re: performance surprise -- why?
... > CCCTAAACCCTAAACCCTAAACCCTAAACCTCTGAATCCTTAATCCCTAAATCCCTAAAT...(30MB string). ... The substitution method must move parts of the ... The results show indexing and global matching in the same ballpark, ... sub substitute { ...
(comp.lang.perl.misc)
• Re: Regex in a variable
... *arbitrary* regexes) by: ... delimiters but matching ones. ... Or if the /e option is used with the substitution operator. ...
(perl.beginners)
• A couple of questions regarding runtime generation of REGEXPs
... resolution to this, once and for all. ... Apparently qr// will only function on the matching side, ... Even though qrwill pass warnings and errors, ... even though the substitution is constant ...
(comp.lang.perl.misc)