Sdes P10 And P8 Key Generation

  1. Sdes P10 And P8 Key Generation Price
An Algorithm to implement Simplified-DES encryption
Sdes p10 and p8 key generation download
Simplified-DES.cpp

/arcade-town-games-key-generator.html. Step6: 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. Question: Look Up S-DES (you Can Use Your Main Book Or An Online Source), And Solve The Following: Based On S-DES Key Generation, If The Input Of P8 In Round 2 Is, Find The Shared 10-bit Key K. P10: 3 5 2 74 10 9 8 6 P8: 6 348 510 9 And The Diagram For Key Generation Is The Following: 6 10-bit Key 10 P 10 LS-1 LS-1 P 8 K2 LS-2 LS-2 P 8.

Key
// Algorithm to implement simplified - DES encryption
#include<bits/stdc++.h>
usingnamespacestd;
string Permutation(vector<int> array, string inp){
string out = '';
for(int i=0;i<array.size();i++)
out += inp[array[i]-1];
return out;
}
classS_DES{
public:
string KEY,K1,K2,IPOut,InvIPOut;
string F1Out;
string INPUT,OUTPUT;
voidinitialize(string key){
if(key.size()!=10){
cout<<'nInValid Key-Length '<<key<<''<<key.size();
exit(1);
}
KEY = key;
Keys_Generation();
}
voidKeys_Generation(){
cout<<'Enter P10 permutation array: ';
vector<int> P10(10,0);
for(int i=0;i<10;i++)
cin>>P10[i];
string P10_output = Permutation(P10,KEY);
cout<<'P10 output while generating key: '<<P10_output<<endl;
string P10_left = P10_output.substr(0,5), P10_right = P10_output.substr(5,5);
string pl = LShift(P10_left,1), pr = LShift(P10_right,1);
string plpr = pl+pr;
cout<<'Enter P8 permutation array: ';
vector<int> P8(10,0);
for(int i=0;i<8;i++)
cin>>P8[i];
K1 = Permutation(P8,plpr);
cout<<'K1: '<<K1<<endl;
string pl1=LShift(pl,2), pr1=LShift(pr,2);
plpr = pl1+pr1;
K2 = Permutation(P8,plpr);
cout<<'K2: '<<K2<<endl;
}
string LShift(string input,int n){
string output = input;
char firstbit;
while(n--){
firstbit = output[0];
output = output.substr(1,output.size()-1);
output += firstbit;
}
return output;
}
voidDES_Encryption(){
IP();
string LIP = IPOut.substr(0,4);
string RIP = IPOut.substr(4,4);
cout<<'IP output: '<<IPOut<<endl;
Function_F(LIP,RIP,1);
cout<<'Fn Output: '<<F1Out<<endl;
string L1 = F1Out.substr(0,4), R1 = F1Out.substr(4,4);
Function_F(R1,L1,2);
cout<<'Fn Output second time: '<<F1Out<<endl;
InvIP(F1Out);
cout<<'Encrypted Cipher-string: '<<InvIPOut<<endl;
}
/*Method to perform Initial-Permutation*/
voidIP(){
vector<int> IP_array(8,0);
cout<<'Enter initial Permutation array: ';
for(int i=0;i<8;i++)
cin>>IP_array[i];
IPOut = Permutation(IP_array,INPUT);
}
/*Method to perform Inverse of Initial-Permutation*/
voidInvIP(string input){
vector<int> InvIPArray(8,0);
cout<<'Enter Inverse initial Permutation: ';
for(int i=0;i<8;i++)
cin>>InvIPArray[i];
InvIPOut = Permutation(InvIPArray,input);
}
voidFunction_F(string linput,string rinput,int key)
{
cout<<'Enter E/P array: ';
vector<int> E_P(8,0);
for(int i=0;i<8;i++)
cin>>E_P[i];
string E_POutput = Permutation(E_P,rinput);
string EXOR_Output;
if(key 1)
EXOR_Output = EX_OR(E_POutput,K1);
else
EXOR_Output = EX_OR(E_POutput,K2);
string LEXOR = EXOR_Output.substr(0,4),REXOR = EXOR_Output.substr(4,4);
string SBOX0_Output=SBOX0(LEXOR);
string SBOX1_Output=SBOX1(REXOR);
string SBOX_Output = SBOX0_Output+SBOX1_Output;
cout<<'Enter P4 Operation array: ';
vector<int> P4(4,0);
for(int i=0;i<4;i++)
cin>>P4[i];
string P4_Output = Permutation(P4,SBOX_Output);
string fk_Output = EX_OR(P4_Output,linput);
F1Out = fk_Output + rinput;
}
string EX_OR(string a,string b){
string output = '';
for(int i=0;i<a.size();i++){
if(a[i] b[i])
output += '0';
else
output += '1';
}
return output;
}
string SBOX0(string l)
{
cout<<'Enter Input for S0n';
vector<int> temp(4,0);
vector<vector<int> > S0(4,temp);
for(int i=0;i<4;i++){
for(int j = 0;j<4;j++)
cin>>S0[i][j];
}
string bits[]={'00','01','10','11'};
string lrow = l.substr(0,1)+l.substr(3,1),lcol = l.substr(1,1)+l.substr(2,1);
string SO;
int i,lr,lc,b;
for(i=0;i<4;i++){
if(lrow bits[i])
lr=i;
if(lcol bits[i])
lc=i;
}
b=S0[lr][lc];
return bits[b];
}
string SBOX1(string l)
{
cout<<'Enter Input for S1n';
vector<int> temp(4,0);
vector<vector<int> > S0(4,temp);
for(int i=0;i<4;i++){
for(int j = 0;j<4;j++)
cin>>S0[i][j];
}
string bits[]={'00','01','10','11'};
string lrow = l.substr(0,1)+l.substr(3,1),lcol = l.substr(1,1)+l.substr(2,1);
string SO;
int i,lr,lc,b;
for(i=0;i<4;i++){
if(lrow bits[i])
lr=i;
if(lcol bits[i])
lc=i;
}
b=S0[lr][lc];
return bits[b];
}
};
intmain()
{
int i,n=10,choice;
string key;
S_DES S;
while(1){
cout<<'nWhat do you want to do.n1. Encryptionn2. ExitnnEnter the choice? ';
cin>>choice;
switch(choice){
case1:
cout<<'nEnter the 10-bits KEY: ';
cin>>key;
cout<<'nNotedown this key, as same key is used for Decryptionn';
S.initialize(key);
cout<<'Enter string to encrypt: ';
cin>>S.INPUT;
S.DES_Encryption();
break;
case2:
exit(0);
default:
cout<<'nWrong Choice Enter againnPress any key to return to Main Menu.';
break;
}
}
return0;
}

Sdes P10 And P8 Key Generation Price

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment