S-des Key Generation Code In C

Posted on by
Key

Mar 24, 2010  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. Apr 11, 2014  DES.c and DES.h contain the functions used in the DES algorithm. Main.c builds the algorithm and allows you to encrypt/decrypt an input file. Use make to build desbox. $ make $ desbox -help genkey.c is a key generator that prevents weak keys. Use it if you don't have any key to use. Use make to build the keygen. $ make genkey $./genkey.

May 14, 2016  Here, a foreign key of 1 in the categoryid column will relate to food expenses, a foreign key of 2 will relate to accommodation expenses, and so forth. Let's dive in. Generate Models. To start off, I created a new rails application and established the primary database, expenses. Rails migration foreign key.

Web It is kept safe from your PC, Mac, and Smartphones against online threats. This security will manage all of your family’s safety when you are posting photos, shopping online, and sending emails. It will notify you about harmful websites and apps.

An Algorithm to implement Simplified-DES encryption
Simplified-DES.cpp
// 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;
}

S-des Key Generation Code In China

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