SlideShare a Scribd company logo
1 of 1
Download to read offline
Task 4 : The key is hardcoded in the provided source DES encryption/decryption programs.
Please change the source code files of the DES encryption/decryption programs, so that the key
would be entered through the command line as the 4th input argument.
SOURCE CODE FOR ENCODE: #include<iostream> #include<fstream> #include<sstream>
#include<string> using namespace std; #include"cryptopp/cryptlib.h" #include"cryptopp/hex.h"
#include"cryptopp/filters.h" #include"cryptopp/des.h" #include"cryptopp/modes.h" using
namespace CryptoPP; string des_encode(string & plain,byte key[]) { string cipher; try { //cout <<
"plain text: " << plain << endl; ECB_Mode<DES>::Encryption enc; enc.SetKey(key,
DES::DEFAULT_KEYLENGTH); StringSource(plain, true, new StreamTransformationFilter(enc,
new StringSink(cipher)));//add padding by StreamTransformationFilter } catch(const
CryptoPP::Exception& e) { cerr << e.what() << endl; exit(1); } return cipher; } int main(int argc, char
* argv[]) { ifstream file1; ofstream file2; byte
key[DES::DEFAULT_KEYLENGTH]={'1','2','3','4','a','b','c','d'}; //key is hardcoded if(argc!=3) {
cout<<"usage:des_encode infile outfile" << endl; } cout << " The input file name is " << argv [1] <<
endl; cout << " The output file name is " << argv [2] << endl; file1.open(argv[1]);
file2.open(argv[2]); //reading stringstream buffer; buffer << file1.rdbuf(); string plain(buffer.str());
//print key string encoded; encoded.clear(); StringSource(key, sizeof(key), true, new HexEncoder(
new StringSink(encoded))); cout << "key: " << encoded << endl; //encrypt string
cipher=des_encode(plain,key); file2<<cipher; cout<<"cipher text stored in:"<<argv[2]<<endl;
file1.close(); file2.close(); return 0; }
SOURCE CODE FOR DECODE: #include<iostream> #include<fstream> #include<sstream>
#include<string> using namespace std; #include"cryptopp/cryptlib.h" #include"cryptopp/hex.h"
#include"cryptopp/filters.h" #include"cryptopp/des.h" #include"cryptopp/modes.h" using
namespace CryptoPP; string des_decode(string & cipher,byte key[]) { string plain; //decryption try {
ECB_Mode< DES >::Decryption dec; dec.SetKey(key, DES::DEFAULT_KEYLENGTH);
StringSource s(cipher, true, new StreamTransformationFilter(dec, new StringSink(plain))); cout <<
"recovered text: " << plain<< endl; } catch(const CryptoPP::Exception& e) { cerr << e.what() <<
endl; exit(1); } return plain; } int main(int argc,char * argv[]) { ifstream file1; ofstream file2; byte
key[DES::DEFAULT_KEYLENGTH]={'1','2','3','4','a','b','c','d'}; //key is hardcoded; if(argc!=3) {
cout<<"usage:des_decode infile outfile" <<endl; } cout << " The input file name is " << argv [1] <<
endl; cout << " The output file name is " << argv [2] << endl; file1.open(argv[1]);
file2.open(argv[2]); //reading stringstream buffer; buffer << file1.rdbuf(); string cipher(buffer.str());
//print key string encoded; encoded.clear(); StringSource(key, sizeof(key), true, new HexEncoder(
new StringSink(encoded))); cout << "key: " << encoded << endl; //decryption; string
plain=des_decode(cipher,key); file2<<plain; cout<<"plain text stored in:"<<argv[2]<<endl;
file1.close(); file2.close(); return 0; }

More Related Content

Similar to Task 4 The key is hardcoded in the provided source DES enc.pdf

Computer Security Laboratory Manual .pdf
Computer Security Laboratory Manual .pdfComputer Security Laboratory Manual .pdf
Computer Security Laboratory Manual .pdfDebebeKebede
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsAleksandr Yampolskiy
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen OomsAjay Ohri
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdfTECHNOLOGY CONTROL CO.
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in rubyHiroshi Nakamura
 
Implement symmetric key algorithms.pptx
Implement symmetric key algorithms.pptxImplement symmetric key algorithms.pptx
Implement symmetric key algorithms.pptxpreethihp4500
 
Slide cipher based encryption
Slide cipher based encryptionSlide cipher based encryption
Slide cipher based encryptionMizi Mohamad
 
Develop an encryption and decryption algorithm Your program should a.pdf
Develop an encryption and decryption algorithm  Your program should a.pdfDevelop an encryption and decryption algorithm  Your program should a.pdf
Develop an encryption and decryption algorithm Your program should a.pdfdeepaksatrker
 
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdfDirections# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdftxkev
 
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxLab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxDIPESH30
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfaggarwalshoppe14
 
Unit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptxUnit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptxVishwanathMahalle
 
Redis for your boss
Redis for your bossRedis for your boss
Redis for your bossElena Kolevska
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keysDr. Edwin Hernandez
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)securityEnrico Zimuel
 
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding kadalisrikanth
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptographyErik LaBianca
 

Similar to Task 4 The key is hardcoded in the provided source DES enc.pdf (20)

Computer Security Laboratory Manual .pdf
Computer Security Laboratory Manual .pdfComputer Security Laboratory Manual .pdf
Computer Security Laboratory Manual .pdf
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programs
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen Ooms
 
Python Cryptography & Security
Python Cryptography & SecurityPython Cryptography & Security
Python Cryptography & Security
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in ruby
 
Implement symmetric key algorithms.pptx
Implement symmetric key algorithms.pptxImplement symmetric key algorithms.pptx
Implement symmetric key algorithms.pptx
 
Slide cipher based encryption
Slide cipher based encryptionSlide cipher based encryption
Slide cipher based encryption
 
Develop an encryption and decryption algorithm Your program should a.pdf
Develop an encryption and decryption algorithm  Your program should a.pdfDevelop an encryption and decryption algorithm  Your program should a.pdf
Develop an encryption and decryption algorithm Your program should a.pdf
 
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdfDirections# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
 
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docxLab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdf
 
Unit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptxUnit-III_3R-CRYPTO_2021-22_VSM.pptx
Unit-III_3R-CRYPTO_2021-22_VSM.pptx
 
Redis for your boss
Redis for your bossRedis for your boss
Redis for your boss
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keys
 
Serialization in Go
Serialization in GoSerialization in Go
Serialization in Go
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
 
Usp
UspUsp
Usp
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptography
 

More from abcfootcare

Monroe Manufacturing has a quick ratio of 200x 28125 in .pdf
Monroe Manufacturing has a quick ratio of 200x 28125 in .pdfMonroe Manufacturing has a quick ratio of 200x 28125 in .pdf
Monroe Manufacturing has a quick ratio of 200x 28125 in .pdfabcfootcare
 
Libertarian paternalism is defined as aGroup of answer cho.pdf
Libertarian paternalism is defined as aGroup of answer cho.pdfLibertarian paternalism is defined as aGroup of answer cho.pdf
Libertarian paternalism is defined as aGroup of answer cho.pdfabcfootcare
 
La utilidad neta para el ao en curso fue de 30000 Los si.pdf
La utilidad neta para el ao en curso fue de 30000 Los si.pdfLa utilidad neta para el ao en curso fue de 30000 Los si.pdf
La utilidad neta para el ao en curso fue de 30000 Los si.pdfabcfootcare
 
La cuenta Cash Over y Short a No es necesario en un siste.pdf
La cuenta Cash Over y Short  a No es necesario en un siste.pdfLa cuenta Cash Over y Short  a No es necesario en un siste.pdf
La cuenta Cash Over y Short a No es necesario en un siste.pdfabcfootcare
 
Los profesores Michael Halbert y Dwight Scott predicen que l.pdf
Los profesores Michael Halbert y Dwight Scott predicen que l.pdfLos profesores Michael Halbert y Dwight Scott predicen que l.pdf
Los profesores Michael Halbert y Dwight Scott predicen que l.pdfabcfootcare
 
Ltfen 1994 Meksika Pesosu Krizini aklaynz zellikle lt.pdf
Ltfen 1994 Meksika Pesosu Krizini aklaynz  zellikle lt.pdfLtfen 1994 Meksika Pesosu Krizini aklaynz  zellikle lt.pdf
Ltfen 1994 Meksika Pesosu Krizini aklaynz zellikle lt.pdfabcfootcare
 
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdf
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdfFirmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdf
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdfabcfootcare
 
Estudio de caso 52 Transparencia Fiscal Qu es justo La.pdf
Estudio de caso 52  Transparencia Fiscal  Qu es justo La.pdfEstudio de caso 52  Transparencia Fiscal  Qu es justo La.pdf
Estudio de caso 52 Transparencia Fiscal Qu es justo La.pdfabcfootcare
 
Is there a case study of a business that employed retained e.pdf
Is there a case study of a business that employed retained e.pdfIs there a case study of a business that employed retained e.pdf
Is there a case study of a business that employed retained e.pdfabcfootcare
 
Cul es el tipo de cognicin que es evidente en el nio en .pdf
Cul es el tipo de cognicin que es evidente en el nio en .pdfCul es el tipo de cognicin que es evidente en el nio en .pdf
Cul es el tipo de cognicin que es evidente en el nio en .pdfabcfootcare
 
Ha perdido la publicidad televisiva su poder Adopte una po.pdf
Ha perdido la publicidad televisiva su poder Adopte una po.pdfHa perdido la publicidad televisiva su poder Adopte una po.pdf
Ha perdido la publicidad televisiva su poder Adopte una po.pdfabcfootcare
 
If a firms sources of funds have been as listed in the foll.pdf
If a firms sources of funds have been as listed in the foll.pdfIf a firms sources of funds have been as listed in the foll.pdf
If a firms sources of funds have been as listed in the foll.pdfabcfootcare
 
In java and based upon a txt file please add the first FOUR.pdf
In java and based upon a txt file please add the first FOUR.pdfIn java and based upon a txt file please add the first FOUR.pdf
In java and based upon a txt file please add the first FOUR.pdfabcfootcare
 
En cul de las siguientes situaciones esperara que el dla.pdf
En cul de las siguientes situaciones esperara que el dla.pdfEn cul de las siguientes situaciones esperara que el dla.pdf
En cul de las siguientes situaciones esperara que el dla.pdfabcfootcare
 
En los Estados Unidos la formacin y el desarrollo tienden .pdf
En los Estados Unidos la formacin y el desarrollo tienden .pdfEn los Estados Unidos la formacin y el desarrollo tienden .pdf
En los Estados Unidos la formacin y el desarrollo tienden .pdfabcfootcare
 
evaluate the importance of stakeholders especially in LoLC i.pdf
evaluate the importance of stakeholders especially in LoLC i.pdfevaluate the importance of stakeholders especially in LoLC i.pdf
evaluate the importance of stakeholders especially in LoLC i.pdfabcfootcare
 
Tim tiene preferencias racionales A y Jim tiene preferencia.pdf
Tim tiene preferencias racionales A y Jim tiene preferencia.pdfTim tiene preferencias racionales A y Jim tiene preferencia.pdf
Tim tiene preferencias racionales A y Jim tiene preferencia.pdfabcfootcare
 
E183 Restricciones y designaciones de activos Un hospital.pdf
E183 Restricciones y designaciones de activos Un hospital.pdfE183 Restricciones y designaciones de activos Un hospital.pdf
E183 Restricciones y designaciones de activos Un hospital.pdfabcfootcare
 
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdf
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdfEcuacin de efectivo Blitz Corp tiene un valor en libros d.pdf
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdfabcfootcare
 
Compare and contrast neurotransmitter receptor proteins with.pdf
Compare and contrast neurotransmitter receptor proteins with.pdfCompare and contrast neurotransmitter receptor proteins with.pdf
Compare and contrast neurotransmitter receptor proteins with.pdfabcfootcare
 

More from abcfootcare (20)

Monroe Manufacturing has a quick ratio of 200x 28125 in .pdf
Monroe Manufacturing has a quick ratio of 200x 28125 in .pdfMonroe Manufacturing has a quick ratio of 200x 28125 in .pdf
Monroe Manufacturing has a quick ratio of 200x 28125 in .pdf
 
Libertarian paternalism is defined as aGroup of answer cho.pdf
Libertarian paternalism is defined as aGroup of answer cho.pdfLibertarian paternalism is defined as aGroup of answer cho.pdf
Libertarian paternalism is defined as aGroup of answer cho.pdf
 
La utilidad neta para el ao en curso fue de 30000 Los si.pdf
La utilidad neta para el ao en curso fue de 30000 Los si.pdfLa utilidad neta para el ao en curso fue de 30000 Los si.pdf
La utilidad neta para el ao en curso fue de 30000 Los si.pdf
 
La cuenta Cash Over y Short a No es necesario en un siste.pdf
La cuenta Cash Over y Short  a No es necesario en un siste.pdfLa cuenta Cash Over y Short  a No es necesario en un siste.pdf
La cuenta Cash Over y Short a No es necesario en un siste.pdf
 
Los profesores Michael Halbert y Dwight Scott predicen que l.pdf
Los profesores Michael Halbert y Dwight Scott predicen que l.pdfLos profesores Michael Halbert y Dwight Scott predicen que l.pdf
Los profesores Michael Halbert y Dwight Scott predicen que l.pdf
 
Ltfen 1994 Meksika Pesosu Krizini aklaynz zellikle lt.pdf
Ltfen 1994 Meksika Pesosu Krizini aklaynz  zellikle lt.pdfLtfen 1994 Meksika Pesosu Krizini aklaynz  zellikle lt.pdf
Ltfen 1994 Meksika Pesosu Krizini aklaynz zellikle lt.pdf
 
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdf
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdfFirmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdf
Firmalarn ve finansal kurumlarn bir faiz oran takasna katlma.pdf
 
Estudio de caso 52 Transparencia Fiscal Qu es justo La.pdf
Estudio de caso 52  Transparencia Fiscal  Qu es justo La.pdfEstudio de caso 52  Transparencia Fiscal  Qu es justo La.pdf
Estudio de caso 52 Transparencia Fiscal Qu es justo La.pdf
 
Is there a case study of a business that employed retained e.pdf
Is there a case study of a business that employed retained e.pdfIs there a case study of a business that employed retained e.pdf
Is there a case study of a business that employed retained e.pdf
 
Cul es el tipo de cognicin que es evidente en el nio en .pdf
Cul es el tipo de cognicin que es evidente en el nio en .pdfCul es el tipo de cognicin que es evidente en el nio en .pdf
Cul es el tipo de cognicin que es evidente en el nio en .pdf
 
Ha perdido la publicidad televisiva su poder Adopte una po.pdf
Ha perdido la publicidad televisiva su poder Adopte una po.pdfHa perdido la publicidad televisiva su poder Adopte una po.pdf
Ha perdido la publicidad televisiva su poder Adopte una po.pdf
 
If a firms sources of funds have been as listed in the foll.pdf
If a firms sources of funds have been as listed in the foll.pdfIf a firms sources of funds have been as listed in the foll.pdf
If a firms sources of funds have been as listed in the foll.pdf
 
In java and based upon a txt file please add the first FOUR.pdf
In java and based upon a txt file please add the first FOUR.pdfIn java and based upon a txt file please add the first FOUR.pdf
In java and based upon a txt file please add the first FOUR.pdf
 
En cul de las siguientes situaciones esperara que el dla.pdf
En cul de las siguientes situaciones esperara que el dla.pdfEn cul de las siguientes situaciones esperara que el dla.pdf
En cul de las siguientes situaciones esperara que el dla.pdf
 
En los Estados Unidos la formacin y el desarrollo tienden .pdf
En los Estados Unidos la formacin y el desarrollo tienden .pdfEn los Estados Unidos la formacin y el desarrollo tienden .pdf
En los Estados Unidos la formacin y el desarrollo tienden .pdf
 
evaluate the importance of stakeholders especially in LoLC i.pdf
evaluate the importance of stakeholders especially in LoLC i.pdfevaluate the importance of stakeholders especially in LoLC i.pdf
evaluate the importance of stakeholders especially in LoLC i.pdf
 
Tim tiene preferencias racionales A y Jim tiene preferencia.pdf
Tim tiene preferencias racionales A y Jim tiene preferencia.pdfTim tiene preferencias racionales A y Jim tiene preferencia.pdf
Tim tiene preferencias racionales A y Jim tiene preferencia.pdf
 
E183 Restricciones y designaciones de activos Un hospital.pdf
E183 Restricciones y designaciones de activos Un hospital.pdfE183 Restricciones y designaciones de activos Un hospital.pdf
E183 Restricciones y designaciones de activos Un hospital.pdf
 
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdf
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdfEcuacin de efectivo Blitz Corp tiene un valor en libros d.pdf
Ecuacin de efectivo Blitz Corp tiene un valor en libros d.pdf
 
Compare and contrast neurotransmitter receptor proteins with.pdf
Compare and contrast neurotransmitter receptor proteins with.pdfCompare and contrast neurotransmitter receptor proteins with.pdf
Compare and contrast neurotransmitter receptor proteins with.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Task 4 The key is hardcoded in the provided source DES enc.pdf

  • 1. Task 4 : The key is hardcoded in the provided source DES encryption/decryption programs. Please change the source code files of the DES encryption/decryption programs, so that the key would be entered through the command line as the 4th input argument. SOURCE CODE FOR ENCODE: #include<iostream> #include<fstream> #include<sstream> #include<string> using namespace std; #include"cryptopp/cryptlib.h" #include"cryptopp/hex.h" #include"cryptopp/filters.h" #include"cryptopp/des.h" #include"cryptopp/modes.h" using namespace CryptoPP; string des_encode(string & plain,byte key[]) { string cipher; try { //cout << "plain text: " << plain << endl; ECB_Mode<DES>::Encryption enc; enc.SetKey(key, DES::DEFAULT_KEYLENGTH); StringSource(plain, true, new StreamTransformationFilter(enc, new StringSink(cipher)));//add padding by StreamTransformationFilter } catch(const CryptoPP::Exception& e) { cerr << e.what() << endl; exit(1); } return cipher; } int main(int argc, char * argv[]) { ifstream file1; ofstream file2; byte key[DES::DEFAULT_KEYLENGTH]={'1','2','3','4','a','b','c','d'}; //key is hardcoded if(argc!=3) { cout<<"usage:des_encode infile outfile" << endl; } cout << " The input file name is " << argv [1] << endl; cout << " The output file name is " << argv [2] << endl; file1.open(argv[1]); file2.open(argv[2]); //reading stringstream buffer; buffer << file1.rdbuf(); string plain(buffer.str()); //print key string encoded; encoded.clear(); StringSource(key, sizeof(key), true, new HexEncoder( new StringSink(encoded))); cout << "key: " << encoded << endl; //encrypt string cipher=des_encode(plain,key); file2<<cipher; cout<<"cipher text stored in:"<<argv[2]<<endl; file1.close(); file2.close(); return 0; } SOURCE CODE FOR DECODE: #include<iostream> #include<fstream> #include<sstream> #include<string> using namespace std; #include"cryptopp/cryptlib.h" #include"cryptopp/hex.h" #include"cryptopp/filters.h" #include"cryptopp/des.h" #include"cryptopp/modes.h" using namespace CryptoPP; string des_decode(string & cipher,byte key[]) { string plain; //decryption try { ECB_Mode< DES >::Decryption dec; dec.SetKey(key, DES::DEFAULT_KEYLENGTH); StringSource s(cipher, true, new StreamTransformationFilter(dec, new StringSink(plain))); cout << "recovered text: " << plain<< endl; } catch(const CryptoPP::Exception& e) { cerr << e.what() << endl; exit(1); } return plain; } int main(int argc,char * argv[]) { ifstream file1; ofstream file2; byte key[DES::DEFAULT_KEYLENGTH]={'1','2','3','4','a','b','c','d'}; //key is hardcoded; if(argc!=3) { cout<<"usage:des_decode infile outfile" <<endl; } cout << " The input file name is " << argv [1] << endl; cout << " The output file name is " << argv [2] << endl; file1.open(argv[1]); file2.open(argv[2]); //reading stringstream buffer; buffer << file1.rdbuf(); string cipher(buffer.str()); //print key string encoded; encoded.clear(); StringSource(key, sizeof(key), true, new HexEncoder( new StringSink(encoded))); cout << "key: " << encoded << endl; //decryption; string plain=des_decode(cipher,key); file2<<plain; cout<<"plain text stored in:"<<argv[2]<<endl; file1.close(); file2.close(); return 0; }