S-des Key Generation Code In C%2b%2b

S-des key generation code in c 2b 2b 1S-des

S-des Key Generation Code In C 2b 2b 4

Key

We rearrange 32bit text by following the order of that matrix. See the matrix in below code After expansion permutation we have to XOR the output 48bit with a 48bit sub key. Let see how that 48bit sub key generating from 64bit original key. Permutated Choice 1: Initially we take a 64 bit key and then apply to permutated choice 1. As we know S-DES has two round and for that we also need two keys, one key we generate in the above steps (step 1 to step 5). Now we need to generate a second bit and after that we will move to encrypt the plain text or message. It is simple to generate the second key. Simply, go in step 4 copy both halves, each one consists of 5 bits.

S-des Key Generation Code In C 2b 2b 1

P: 2
I have been asked to do a DES encryption project in C but pretty new to programming. I've found the following code in C++ but am not sure how to do the equivalent of classes in C.
I dont know the syntax of how to move from one section of code to the next. Do i have to declare seperate functions for each section even if its only a simple for loop section of code? for example how would i move from:
void Des::IP() //Initial Permutation -----> void Des::Expansio() //Permutation Choice-1
in code below:
  1. # include <stdio.h>
  2. # include <fstream.h>
  3. # include <string.h>
  4. # include <conio.h>
  5. # include <iostream.h>
  6. int key[64]={
  7. 0,0,0,1,0,0,1,1,
  8. 0,0,1,1,0,1,0,0,
  9. 0,1,0,1,0,1,1,1,
  10. 0,1,1,1,1,0,0,1,
  11. 1,0,0,1,1,0,1,1,
  12. 1,0,1,1,1,1,0,0,
  13. 1,1,0,1,1,1,1,1,
  14. 1,1,1,1,0,0,0,1
  15. };
  16. class Des
  17. {
  18. public:
  19. int keyi[16][48],
  20. total[64],
  21. left[32],
  22. right[32],
  23. ck[28],
  24. dk[28],
  25. expansion[48],
  26. z[48],
  27. xor1[48],
  28. sub[32],
  29. p[32],
  30. xor2[32],
  31. temp[64],
  32. pc1[56],
  33. ip[64],
  34. inv[8][8];
  35. char final[1000];
  36. void IP();
  37. void PermChoice1();
  38. void PermChoice2();
  39. void Expansion();
  40. void inverse();
  41. void xor_two();
  42. void xor_oneE(int);
  43. void xor_oneD(int);
  44. void substitution();
  45. void permutation();
  46. void keygen();
  47. char * Encrypt(char *);
  48. char * Decrypt(char *);
  49. };
  50. void Des::IP() //Initial Permutation
  51. {
  52. int k=58,i;
  53. for(i=0;i<32;i++)
  54. {
  55. ip[i]=total[k-1];
  56. if(k-8>0) k=k-8;
  57. else k=k+58;
  58. }
  59. k=57;
  60. for( i=32;i<64;i++)
  61. {
  62. ip[i]=total[k-1];
  63. if(k-8>0) k=k-8;
  64. else k=k+58;
  65. }
  66. }
  67. void Des::PermChoice1() //Permutation Choice-1
  68. {
  69. int k=57,i;
  70. for(i=0;i<28;i++)
  71. {
  72. pc1[i]=key[k-1];
  73. if(k-8>0) k=k-8;
  74. else k=k+57;
  75. }
  76. k=63;
  77. for( i=28;i<52;i++)
  78. {
  79. pc1[i]=key[k-1];
  80. if(k-8>0) k=k-8;
  81. else k=k+55;
  82. }
  83. k=28;
  84. for(i=52;i<56;i++)
  85. {
  86. pc1[i]=key[k-1];
  87. k=k-8;
  88. }
  89. }