Thread: Help with Permutation

  1. #1
    *this
    Join Date
    Mar 2005
    Posts
    498

    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
    Last edited by JoshR; 07-06-2005 at 07:52 PM.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    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.
    Away.

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    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. #4
    *this
    Join Date
    Mar 2005
    Posts
    498
    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. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    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 subscribe to a feed

Similar Threads

  1. bit level permutation function
    By zxcv in forum C Programming
    Replies: 2
    Last Post: 07-27-2008, 01:26 PM
  2. Problem creating a recursive string permutation function
    By indigo0086 in forum C++ Programming
    Replies: 4
    Last Post: 10-10-2006, 10:09 AM
  3. Sorting: Getting permutation index array
    By flyvholm in forum C Programming
    Replies: 2
    Last Post: 09-20-2006, 07:07 PM
  4. Permutation Calculation
    By Eric Hansen in forum C++ Programming
    Replies: 21
    Last Post: 06-11-2003, 04:03 PM
  5. INT ARRAY Permutation!
    By arthur5005 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2002, 05:30 AM