473,394 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Permutation

Hi, well I need to permute a variable of 64 bits according to the following table, so could you please tell me how to accomplish that:

PC-1

57 49 41 33 25 17 9
1 58 50 42 34 26 18
10 2 59 51 43 35 27
19 11 3 60 52 44 36
63 55 47 39 31 23 15
7 62 54 46 38 30 22
14 6 61 53 45 37 29
21 13 5 28 20 12 4

you know this works as follow: if the variable that is goig to be permuted is
K = 00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001

Since the first entry in the table is "57", this means that the 57th bit of the original variable K becomes the first bit of the permuted variable K+. The 49th bit of the original variable becomes the second bit of the permuted variable. The 4th bit of the original variable is the last bit of the permuted variable, and this will be the permuted variable K+
K+ = 1111000 0110011 0010101 0101111 0101010 1011001 1001111 0001111

Thanks for your help.
Aug 11 '06 #1
6 3028
Banfa
9,065 Expert Mod 8TB
To start with your array of numbers only has 56 entries but assuming it has 64 then start with a 64 bit variable set to 0, for each number in turn locate the bit and coipy it to the right place

for instance the 3rd number (index 2) is 41

long long K = ....;
long long result = 0;

if ( K & (1<<(41-1)) != 0 )
{
result |= 1<<(3-1);
}
Aug 11 '06 #2
So, I have to write the code that you gave me 56 times, or there is a way to put this code in a repetitive way. Thanks for your help. Edwin Alvear
Aug 15 '06 #3
I mean do I have to do it like this:


if ( K & (d<<(57-1)) != 0 )
{
nuevo |= d<<(1-1);
}

if ( K & (d<<(49-1)) != 0 )
{
nuevo |= d<<(2-1);
}

if ( K & (d<<(41-1)) != 0 )
{
nuevo |= d<<(3-1);
}
. . . . . . . . . . . . . . . . ....... .
Aug 15 '06 #4
Banfa
9,065 Expert Mod 8TB
More or less although it isn't clear where you got d from.

However you would be sensible to define an array of your bit positions as an array

Expand|Select|Wrap|Line Numbers
  1. char table[256] = {
  2.     57 49 41 33 25 17 9
  3.     /* ... more data */
  4. }
  5.  
The you can use a for loop to iterate through the table

Expand|Select|Wrap|Line Numbers
  1. nuevo = 0;
  2.  
  3. for(ix=0; ix<256; ix++)
  4. {
  5.     if ( K & (1<<(table[ix]-1)) != 0 )
  6.     {
  7.         nuevo |= 1<<ix;
  8.     }
  9.  
Aug 15 '06 #5
I will like to know whay the table must have 256 datas if the original one, only 56 datas, and also why the sentence for goes to 256. thanks
Aug 16 '06 #6
Banfa
9,065 Expert Mod 8TB
Mistake :D

The loop has the same number of iterations as the table has entries and should really be

Expand|Select|Wrap|Line Numbers
  1. for(ix=0; ix<sizeof table/sizeof table[0]; ix++)
  2. {
  3. }
  4.  
The table should have the number of entries you require (56 it appears).
Aug 16 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Talin | last post by:
I'm sure I am not the first person to do this, but I wanted to share this: a generator which returns all permutations of a list: def permute( lst ): if len( lst ) == 1: yield lst else: head =...
1
by: user | last post by:
Hello I have Array of 50 ints. I want to receive random permutation, so in each int will be different number from 0-49. Is there any class for permutation ? Thanx Michal
1
by: user | last post by:
Hello I have Array of 50 ints. I want to receive random permutation, so in each int will be different number from 0-49. Is there any class for permutation ? Thanx Michal
1
by: user | last post by:
Hello I have Array of 50 ints. I want to receive random permutation, so in each int will be different number from 0-49. Is there any class for permutation ? Thanx Michal
6
by: badcrusher10 | last post by:
Hello. I'm having trouble figuring out what to do and how to do.. could someone explain to me what I need to do in order to work? THIS IS WHAT I NEED TO DO: Professor Snoop wants a program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.