# Thread: Help with Permutation

1. ## Help with Permutation

I am making an encryption program and I've put together a small permutation header. So far I have come up with the code below and I was wondering what you guys thought of it. Is it a good algorithm? What should I add to make it more unique?

Code:
/* © JoshR | Date Created: 7-06-05 | Last Revision: 7-06-05 */

/* How it works:
* First, value is broken up into two sets A and B
* Binary representation before = 87654321
* Binary representation after  = 5127 8463 [A = 5127  B = 8463]
* Then B is passed through PSub.
* In PSub, if a binary representation = 1001 then,
* The last bit is moved to the front  = 0011
* The front two bits make up the row and the last two make up the column
* in PSBOX[row][col]
* The resulting number is substituted for B and connected with A
* to make the final number
*/

#ifndef PERMUTE_FUNCTIONS_01
#define PERMUTE_FUNCTIONS_01

#include "bitblocks.h"
/////////////////////////////////////////////////
const UCHAR PSBOX[4][4] = { { 3, 14,  5, 15},
{ 8,  1, 10,  4},
{11,  6, 13,  7},
{ 9, 12,  0,  2} };

//-----------------------------------------------
// Returns substituted value dependig on the
// outter bits and middle bits
//-----------------------------------------------

UCHAR PSub (UCHAR val) {
val = (val & 1) * 16; val >>= 1;
return PSBOX[val & 3][val >> 2];
}

//-----------------------------------------------
// Changes order of bits from 87654321 to
// A[5127] B[8463] and passes B to PSub
//-----------------------------------------------

UCHAR Permute (UCHAR val) {
UCHAR A = 0, B = 0;

A += (val & 1) * 4; val >>= 1;
A += (val & 1) * 2; val >>= 1;
B += (val & 1); val >>= 1;
B += (val & 1) * 4; val >>= 1;
A += (val & 1) * 8; val >>= 1;
B += (val & 1) * 2; val >>= 1;
A += (val & 1); val >>= 1;
B += (val & 1) * 8;

return ((A << 4) + PSub(B));
}
//-----------------------------------------------
/////////////////////////////////////////////////

#endif

2. Just a comment - that code is completely reversible without any special knowledge of a key, etc. Unless you have more planned, it's really no sort of encryption at all. If you do have more planned ... this part might be pointless, since encryption comes from algorithms that are not easily reversed, and anything else is just computational overhead. Of course, there might be a good reason for your functions that I'm missing - I am not an expert in encryption.

3. Well this is just a start, its not really done yet but im going to add more tables and make it harder. And maybe add a function that permutes the bits of 8 numbers etc... This in addition to some s-boxes will be a part, just a part of my algorithm. Ya definetly wont be just that I know what your saying, I'm putting together tons of types of algorithms like hash tables, permutation, substitution, compression perhaps.

4. What I meant to say in my first post is I just whipped this up and I want to make it more dynamic where certain numbers could change the final number. I was thinking of having a function that took in more than one number and mixed up the bits between numbers like my code above and then substitute afterwards. What do you think?

5. Sorry for this thread, Nvm about it. If you must know, I decided to use a feistel structure combined with permutation, but instead of functions I created a table for an increase in spead.

Popular pages Recent additions