SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
1- Given an input key ABCDEF0123456789H, and the plaintext 0123456789ABCDEFH,
     perform a one round encryption using DES. Show intermediate results after each
     function.

  Solution:

      Calculations for the first subkey k1:
  -

Input key: ABCDEF0123456789H

                               (TABLE 1-1) Input key 64 bits
                       1        0   1     0     1     0        1       1
                       1        1   0     0     1     1        0       1
                       1        1   1     0     1     1        1       1
                       0        0   0     0     0     0        0       1
                       0        0   1     0     0     0        1       1
                       0        1   0     0     0     1        0       1
                       0        1   1     0     0     1        1       1
                       1        0   0     0     1     0        0       1


                     (TABLE 1-2) Permuted Choice one (PC-1) [56 bits]
                         1    0     0    0     0     1     1
                         1    0     1    1     0     0     1
                         1    0     0    1     0     1     0
                         1    0     1    0     0     0     0

                           0      1     0     1     0     1        0
                           1      0     1     1     0     0        1
                           1      0     1     0     0     0        0
                           1      1     1     0     0     0        0


        (TABLE 1-3) Left Shift by 1 (for round 1) for each 32 bits [C0 D0] separately
                       0      0      0     0      1     1     1
                       0      1      1     0      0     1     1
                       0      0      1     0      1     0     1
                       0      1      0     0      0     0     1

                           1      0     1     0     1     0        1
                           0      1     1     0     0     1        1
                           0      1     0     0     0     0        1
                           1      1     0     0     0     0        0
(TABLE 1-4)Permuted Choice Two (Pc-2) [48 bits Subkey K1]
               1      1      0       0     0       1      0     1
               0      1      1       1     1       1      0     0
               0      0      0       1     0       0      1     0
               1      0      1       1     0       0      0     0
               1      0      1       0     1       1      0     0
               0      0      0       1     1       0      1     0
            Converting LAST table to Hexadecimal yields: C57C12B0AC1AH


                (TABLE 1-5) The plain Text: 0123456789ABCDEFH
                   0   0     0     0     0    0     0   1
                   0   0     1     0     0    0     1   1
                   0   1     0     0     0    1     0   1
                   0   1     1     0     0    1     1   1
                   1   0     0     0     1    0     0   1
                   1   0     1     0     1    0     1   1
                   1   1     0     0     1    1     0   1
                   1   1     1     0     1    1     1   1


           (TABLE 1-6) After Performing Initial Permutation (IP)
                  1     1     0     0     1      1   0      0
                  0     0     0     0     0      0   0      0
                  1     1     0     0     1      1   0      0
                  1     1     1     1     1      1   1      1
                  1     1     1     1     0      0   0      0
                  1     0     1     0     1      0   1      0
                  1     1     1     1     0      0   0      0
                  1     0     1     0     1      0   1      0


(TABLE 1-7) Expansion Permutation (E) for the 32 Right bits produced from the Initial
                                 permutation.
           0        1     1      1      1          0
           1        0     0      0      0          1
           0        1     0      1      0          1
           0        1     0      1      0          1
           0        1     1      1      1          0
           1        0     0      0      0          1
           0        1     0      1      0          1
           0        1     0      1      0          1
(TABLE 1-8)
                          (TABLE 1-4) XOR (TABLE 1-7)
                            Number of Row in the S Boxes
S1              1         0       1       1          1       1
S2              1         1       0       1          1       0
S3              1         0       0       1          0       1
S4              0         0       0       1          1       1
S5              1         1       0       0          1       0
S6              1         0       1       0          1       1
S7              1         0       0       1          0       1
S8              0         0       1       1          1       1
                          Number of Column in the S Box

         (TABLE 1-10) The result of substitution for the S-boxes
0        1     1       1       0       1        1        0
1        1     0       1       0       1        0        1
1        0     0       1       0       1        0        1
1        1     0       1       0       1        0        0

        (TABLE 1-11) The result of permutation P for the last table
1         1     1      0        0      1        1       1
0         0     0      1        0      0        0       1
1         0     1      1        0      0        1       1
0         0     1      1        1      0        1       1

                                  (TABLE 1-12)
                    R1= (TABLE 1-11) XOR (32 lift bits TABLE 1-6)
0           0           1     0       1      0          1    1
0           0           0     1       0      0          0    1
0           1           1     1       1      1          1    1
1           1           0     0       0      1          0    0

                        (TABLE 1-13) OUTPUT OF ROUND 1
        1           1     1    1     0   0   0   0
L1=R0




        1           0     1    0     1   0   1   0
        1           1     1    1     0   0   0   0
        1           0     1    0     1   0   1   0
        0           0     1    0     1   0   1   1
        0           0     0    1     0   0   0   1
R1




        0           1     1    1     1   1   1   1
        1           1     0    0     0   1   0   0
                         IN HEXADECIMAL:
                              L1       R1 :
                               F0AAF0AA2B117FC4H
2- For Des encryption:
(all inputs are in hexadecimal, outputs are in both hexadecimal and binary)
b- Write program that will accept 64bit plaintext and produces Lo and Ro.
(the 32 bit each, left and right output of the initial permutation)
The answer:

The program works as follows:
1-It takes 64bits plaintext in hexadecimal format, that means it accepts 16 digits and only 16digits.
2-If the input data contained spaces it will be removed.
3-you can enter hexadecimal numbers like A or a whether uppercase or lowercase no difference.
4-In case you entered less or larger than 16 Hexadecimal digits. An appropriate message will
appear asking the user to renter correct data.
5-In case you entered any character rather than any one of “0123456789abcdef”or
“0123456789ABCDEF”, for example like “Q” then an appropriate message will appear asking
the user to renter correct hexadecimal data.
6-The output of the program is:
   - The 8X8 binary matrix corresponding for the16 digits hexadecimal data entered.
   - The initial permutation IP 8X8 matrix.(i.e. Lo , Ro in Binary bits)
   - (Lo,Ro) in hexadecimal format.


The Program:

//Solution for problem 2-B

#include <stdio.h>
#include <ctype.h>
#include<iostream.h>
#include<iomanip.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>
void arrange_input_plaintext_to_8_by_8_matrix(void);
void initial_permutation(void);
void conversion_to_hexadecimal_for_bin_permuted(void);
void getting_plaintext_cheking_and_converting_to_decimal(void);
int iptd[16],pt[8][8],ip[8][8];

 int main(void)
        {
               getting_plaintext_cheking_and_converting_to_decimal();
               arrange_input_plaintext_to_8_by_8_matrix();
                initial_permutation();
               return 0;
                }

//This function gets the input plaintext in hexadecimal,checks it and rectifing it from spaces
//moreover it converts it to decimal format
void getting_plaintext_cheking_and_converting_to_decimal(void)
{
int i,t;
char s[1000];
cout<<quot;PLease enter the 64 bits plaintext in Hexadecimal format:quot;<<endl;

xx:
gets(s);
for(i=0;i<strlen(s);i++)
s[i]=tolower(s[i]);

printf(quot;nquot;);
t=-1;
for(i=0;i<strlen(s);i++)
{
if(s[i]!=' ')
{
if((s[i]>=97)&&(s[i]<=102))
{iptd[++t]=s[i]-87;
continue;}
if((s[i]>=48)&&(s[i]<=57))
{iptd[++t]=s[i]-48;
continue;}

else
{printf(quot;nERROR: Not all input data are in Hexadecimal format.nquot;);
printf(quot;n Please renter 64bits plaintext in Hexadecimal format:nquot;);
goto xx;} }
if(s[i]==' ')
continue;

}
if(t!=15)
{cout<<quot;Error: Number of bits entered are not 64.quot;<<endl;
cout<<quot; Please Renter correct 16 hexadecimal numbers:quot;<<endl;
goto xx; }
}

//This function will take the input key text in hexadecimal and it will convert it to BINARY
//
//rearrange the data as 8*8 binary matrix
//THE FUNCTION WILL PRINT out THE DESIREED ARRANGED MATRIX which is ready for the next
stepquot;Permutationquot;

void arrange_input_plaintext_to_8_by_8_matrix(void)
{
        int i,j,n,x,b[4],cpt[16],onedpt[16][4],row,col,t;
        for(i=0;i<=15;i++)
cpt[i]=iptd[i];

for(j=0;j<16;j++)
{for(i=0;i<=3;i++)
{
x=cpt[j]%2;
if(x==0)
{
onedpt[j][3-i]=0;
cpt[j]/=2;}
else
{
onedpt[j][3-i]=1;
cpt[j]=(cpt[j]-1)/2;
}
}}

 row=0;col=0; t=0;
 printf(quot;nThe arranged 8X8 binary matrix corresponding for the entered plain text is:nquot;);
 for(i=0;i<8;i++)
{    printf(quot;nquot;);
for(j=0;j<8;j++)

{pt[i][j]=onedpt[row][col++];
++t;
if(t%4==0)
++row;
printf(quot;%dquot;,pt[i][j]);
if(col>=4)
col=0;}
}}


 /*THIS FUNCTION WILL PERFORM THE INITIAL PERMUTATION FOR THE MATRIX WHICH RESULTED FROM
THE
 AFOREMENTIONED FUNCTION*/
 //ALSO IT WILL PRINT THE PERMUTED RESULT IN BOTH BINARY AND HEXADECIMAL

void initial_permutation(void)
{
int i,j,t=-8,ipt[8][8];
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{if(i<=3)
ip[i][j]=pt[7-j][2*i+1];
if(i>=4)
ip[i][j]=pt[7-j][t]; }
t+=2;}
printf(quot;nThe initial permutaion 8X8 matrix is:nquot;);
 printf(quot;nLo:nquot;);
for(i=0;i<8;i++)
{printf(quot;nquot;);
for(j=0;j<8;j++)
 {if((i==4)&&(j==0))
 printf(quot;nRo:nquot;);
printf(quot; %d quot;,ip[i][j]);
  }
  }
conversion_to_hexadecimal_for_bin_permuted();
 }


//This Function converts the permuted values to hexadecimal and print them all out
void conversion_to_hexadecimal_for_bin_permuted(void)
{
int i,j,r=-1,odw[64],wdw[16][4],hex[64],sum;
                       printf(quot;nquot;);
for(i=0;i<8;i++)
for(j=0;j<8;j++)
odw[++r]=ip[i][j];
r=-1;
printf(quot;nquot;);
for(i=0;i<16;i++)
 for(j=0;j<4;j++)
wdw[i][j]=odw[++r];

for(i=0;i<16;i++)
{
sum=0;
for(j=0;j<4;j++)
sum+=(pow(2,3-j))*wdw[i][j];
hex[i]=sum;}
cout<<quot;In hexadecimal:quot;<<endl;
cout<<quot; Lo quot;<<quot; Ro quot;<<endl;
for(i=0;i<16;i++)
{ if(i==8)
 cout<<' ';
printf(quot;%xquot;,hex[i]);
}
           }

Más contenido relacionado

Similar a Microsoft Word Hw#2

Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
synesthesiapatterns
 
Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
synesthesiapatterns
 
Binary Mathematics Classwork and Hw
Binary Mathematics Classwork and HwBinary Mathematics Classwork and Hw
Binary Mathematics Classwork and Hw
Joji Thompson
 
Mux decod pld2_vs2
Mux decod pld2_vs2Mux decod pld2_vs2
Mux decod pld2_vs2
WanNurdiana
 
Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
synesthesiapatterns
 
Tutorial 0 mth 3201
Tutorial 0 mth 3201Tutorial 0 mth 3201
Tutorial 0 mth 3201
Drradz Maths
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphs
chidabdu
 
Andrew Goldberg. An Efficient Point-to–Point Shortest Path Algorithm
Andrew Goldberg. An Efficient Point-to–Point  Shortest Path AlgorithmAndrew Goldberg. An Efficient Point-to–Point  Shortest Path Algorithm
Andrew Goldberg. An Efficient Point-to–Point Shortest Path Algorithm
Computer Science Club
 
Gerbang logikanya
Gerbang  logikanyaGerbang  logikanya
Gerbang logikanya
pigletpooh
 

Similar a Microsoft Word Hw#2 (20)

16%20 lecture
16%20 lecture16%20 lecture
16%20 lecture
 
Bài tập-des
Bài tập-desBài tập-des
Bài tập-des
 
Informatico
InformaticoInformatico
Informatico
 
Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
 
Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
 
Binary Mathematics Classwork and Hw
Binary Mathematics Classwork and HwBinary Mathematics Classwork and Hw
Binary Mathematics Classwork and Hw
 
Binary addition
Binary additionBinary addition
Binary addition
 
Combinational logic 2
Combinational logic 2Combinational logic 2
Combinational logic 2
 
Crc
CrcCrc
Crc
 
Mux decod pld2_vs2
Mux decod pld2_vs2Mux decod pld2_vs2
Mux decod pld2_vs2
 
Binary operations
 Binary operations Binary operations
Binary operations
 
Gateeee2012q20logicdesign
Gateeee2012q20logicdesignGateeee2012q20logicdesign
Gateeee2012q20logicdesign
 
Gateece2012q19logicdesign
Gateece2012q19logicdesignGateece2012q19logicdesign
Gateece2012q19logicdesign
 
Synesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and ColorsSynesthetic Associational Patterns between Letters and Colors
Synesthetic Associational Patterns between Letters and Colors
 
Tutorial 0 mth 3201
Tutorial 0 mth 3201Tutorial 0 mth 3201
Tutorial 0 mth 3201
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphs
 
Derby presentation
Derby presentationDerby presentation
Derby presentation
 
Andrew Goldberg. An Efficient Point-to–Point Shortest Path Algorithm
Andrew Goldberg. An Efficient Point-to–Point  Shortest Path AlgorithmAndrew Goldberg. An Efficient Point-to–Point  Shortest Path Algorithm
Andrew Goldberg. An Efficient Point-to–Point Shortest Path Algorithm
 
Gerbang logikanya
Gerbang  logikanyaGerbang  logikanya
Gerbang logikanya
 
Gerbang logikanya
Gerbang  logikanyaGerbang  logikanya
Gerbang logikanya
 

Más de kkkseld

Más de kkkseld (9)

Asr
AsrAsr
Asr
 
Microsoft Word The Project, Islam And Science
Microsoft Word   The Project, Islam And ScienceMicrosoft Word   The Project, Islam And Science
Microsoft Word The Project, Islam And Science
 
Speech To Sign Language Interpreter System
Speech To Sign Language Interpreter SystemSpeech To Sign Language Interpreter System
Speech To Sign Language Interpreter System
 
Presentation, Firewalls
Presentation, FirewallsPresentation, Firewalls
Presentation, Firewalls
 
Sslis
SslisSslis
Sslis
 
Mobile Multi Media Applications
Mobile Multi Media ApplicationsMobile Multi Media Applications
Mobile Multi Media Applications
 
Presentation, Firewalls
Presentation, FirewallsPresentation, Firewalls
Presentation, Firewalls
 
Kerie2006 Poster Template 01
Kerie2006 Poster Template 01Kerie2006 Poster Template 01
Kerie2006 Poster Template 01
 
Asr
AsrAsr
Asr
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Microsoft Word Hw#2

  • 1. 1- Given an input key ABCDEF0123456789H, and the plaintext 0123456789ABCDEFH, perform a one round encryption using DES. Show intermediate results after each function. Solution: Calculations for the first subkey k1: - Input key: ABCDEF0123456789H (TABLE 1-1) Input key 64 bits 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 (TABLE 1-2) Permuted Choice one (PC-1) [56 bits] 1 0 0 0 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 (TABLE 1-3) Left Shift by 1 (for round 1) for each 32 bits [C0 D0] separately 0 0 0 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0
  • 2. (TABLE 1-4)Permuted Choice Two (Pc-2) [48 bits Subkey K1] 1 1 0 0 0 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 Converting LAST table to Hexadecimal yields: C57C12B0AC1AH (TABLE 1-5) The plain Text: 0123456789ABCDEFH 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 (TABLE 1-6) After Performing Initial Permutation (IP) 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 (TABLE 1-7) Expansion Permutation (E) for the 32 Right bits produced from the Initial permutation. 0 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1
  • 3. (TABLE 1-8) (TABLE 1-4) XOR (TABLE 1-7) Number of Row in the S Boxes S1 1 0 1 1 1 1 S2 1 1 0 1 1 0 S3 1 0 0 1 0 1 S4 0 0 0 1 1 1 S5 1 1 0 0 1 0 S6 1 0 1 0 1 1 S7 1 0 0 1 0 1 S8 0 0 1 1 1 1 Number of Column in the S Box (TABLE 1-10) The result of substitution for the S-boxes 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1 0 1 0 0 (TABLE 1-11) The result of permutation P for the last table 1 1 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 (TABLE 1-12) R1= (TABLE 1-11) XOR (32 lift bits TABLE 1-6) 0 0 1 0 1 0 1 1 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 (TABLE 1-13) OUTPUT OF ROUND 1 1 1 1 1 0 0 0 0 L1=R0 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 0 0 0 1 R1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 IN HEXADECIMAL: L1 R1 : F0AAF0AA2B117FC4H
  • 4. 2- For Des encryption: (all inputs are in hexadecimal, outputs are in both hexadecimal and binary) b- Write program that will accept 64bit plaintext and produces Lo and Ro. (the 32 bit each, left and right output of the initial permutation) The answer: The program works as follows: 1-It takes 64bits plaintext in hexadecimal format, that means it accepts 16 digits and only 16digits. 2-If the input data contained spaces it will be removed. 3-you can enter hexadecimal numbers like A or a whether uppercase or lowercase no difference. 4-In case you entered less or larger than 16 Hexadecimal digits. An appropriate message will appear asking the user to renter correct data. 5-In case you entered any character rather than any one of “0123456789abcdef”or “0123456789ABCDEF”, for example like “Q” then an appropriate message will appear asking the user to renter correct hexadecimal data. 6-The output of the program is: - The 8X8 binary matrix corresponding for the16 digits hexadecimal data entered. - The initial permutation IP 8X8 matrix.(i.e. Lo , Ro in Binary bits) - (Lo,Ro) in hexadecimal format. The Program: //Solution for problem 2-B #include <stdio.h> #include <ctype.h> #include<iostream.h> #include<iomanip.h> #include <stdlib.h> #include<math.h> #include<string.h> void arrange_input_plaintext_to_8_by_8_matrix(void); void initial_permutation(void); void conversion_to_hexadecimal_for_bin_permuted(void); void getting_plaintext_cheking_and_converting_to_decimal(void); int iptd[16],pt[8][8],ip[8][8]; int main(void) { getting_plaintext_cheking_and_converting_to_decimal(); arrange_input_plaintext_to_8_by_8_matrix(); initial_permutation(); return 0; } //This function gets the input plaintext in hexadecimal,checks it and rectifing it from spaces //moreover it converts it to decimal format void getting_plaintext_cheking_and_converting_to_decimal(void) { int i,t;
  • 5. char s[1000]; cout<<quot;PLease enter the 64 bits plaintext in Hexadecimal format:quot;<<endl; xx: gets(s); for(i=0;i<strlen(s);i++) s[i]=tolower(s[i]); printf(quot;nquot;); t=-1; for(i=0;i<strlen(s);i++) { if(s[i]!=' ') { if((s[i]>=97)&&(s[i]<=102)) {iptd[++t]=s[i]-87; continue;} if((s[i]>=48)&&(s[i]<=57)) {iptd[++t]=s[i]-48; continue;} else {printf(quot;nERROR: Not all input data are in Hexadecimal format.nquot;); printf(quot;n Please renter 64bits plaintext in Hexadecimal format:nquot;); goto xx;} } if(s[i]==' ') continue; } if(t!=15) {cout<<quot;Error: Number of bits entered are not 64.quot;<<endl; cout<<quot; Please Renter correct 16 hexadecimal numbers:quot;<<endl; goto xx; } } //This function will take the input key text in hexadecimal and it will convert it to BINARY // //rearrange the data as 8*8 binary matrix //THE FUNCTION WILL PRINT out THE DESIREED ARRANGED MATRIX which is ready for the next stepquot;Permutationquot; void arrange_input_plaintext_to_8_by_8_matrix(void) { int i,j,n,x,b[4],cpt[16],onedpt[16][4],row,col,t; for(i=0;i<=15;i++) cpt[i]=iptd[i]; for(j=0;j<16;j++) {for(i=0;i<=3;i++) { x=cpt[j]%2; if(x==0) { onedpt[j][3-i]=0; cpt[j]/=2;}
  • 6. else { onedpt[j][3-i]=1; cpt[j]=(cpt[j]-1)/2; } }} row=0;col=0; t=0; printf(quot;nThe arranged 8X8 binary matrix corresponding for the entered plain text is:nquot;); for(i=0;i<8;i++) { printf(quot;nquot;); for(j=0;j<8;j++) {pt[i][j]=onedpt[row][col++]; ++t; if(t%4==0) ++row; printf(quot;%dquot;,pt[i][j]); if(col>=4) col=0;} }} /*THIS FUNCTION WILL PERFORM THE INITIAL PERMUTATION FOR THE MATRIX WHICH RESULTED FROM THE AFOREMENTIONED FUNCTION*/ //ALSO IT WILL PRINT THE PERMUTED RESULT IN BOTH BINARY AND HEXADECIMAL void initial_permutation(void) { int i,j,t=-8,ipt[8][8]; for(i=0;i<8;i++) { for(j=0;j<8;j++) {if(i<=3) ip[i][j]=pt[7-j][2*i+1]; if(i>=4) ip[i][j]=pt[7-j][t]; } t+=2;} printf(quot;nThe initial permutaion 8X8 matrix is:nquot;); printf(quot;nLo:nquot;); for(i=0;i<8;i++) {printf(quot;nquot;); for(j=0;j<8;j++) {if((i==4)&&(j==0)) printf(quot;nRo:nquot;); printf(quot; %d quot;,ip[i][j]); } } conversion_to_hexadecimal_for_bin_permuted(); } //This Function converts the permuted values to hexadecimal and print them all out
  • 7. void conversion_to_hexadecimal_for_bin_permuted(void) { int i,j,r=-1,odw[64],wdw[16][4],hex[64],sum; printf(quot;nquot;); for(i=0;i<8;i++) for(j=0;j<8;j++) odw[++r]=ip[i][j]; r=-1; printf(quot;nquot;); for(i=0;i<16;i++) for(j=0;j<4;j++) wdw[i][j]=odw[++r]; for(i=0;i<16;i++) { sum=0; for(j=0;j<4;j++) sum+=(pow(2,3-j))*wdw[i][j]; hex[i]=sum;} cout<<quot;In hexadecimal:quot;<<endl; cout<<quot; Lo quot;<<quot; Ro quot;<<endl; for(i=0;i<16;i++) { if(i==8) cout<<' '; printf(quot;%xquot;,hex[i]); } }