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