SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
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]);
}
           }

Mais conteúdo relacionado

Semelhante 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
 
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
 
Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_
rofldork
 

Semelhante 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
 
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
 
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
 
Traffic light Controller Design
Traffic light Controller DesignTraffic light Controller Design
Traffic light Controller Design
 
Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_
 
EASA Part 66 Module 5.5 : Logic Circuit
EASA Part 66 Module 5.5 : Logic CircuitEASA Part 66 Module 5.5 : Logic Circuit
EASA Part 66 Module 5.5 : Logic Circuit
 

Mais de kkkseld

Mais 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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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]); } }