SlideShare a Scribd company logo
JAWARIYA JAWAAD 393/BSIT/F19
ANAM SALEEM 398/BSIT/F19
ASSIGNMENT 2
ScreenShots:
Code:
// security.cpp : This file contains the 'main' function. Program execution begins and ends
there.
//
#include <iostream>
#include<string>
using namespace std;
char MsgAutoKey[1000], cip[36], enc[1000], decy[1000];
int keyAK[1000];
class Vig {
public:
string k;
Vig(string k) {
for (int i = 0; i <= k.size(); ++i)
{
if (k[i] >= 'A' && k[i] <= 'Z')
this->k += k[i];
else if (k[i] >= 'a' && k[i] <= 'z')
this->k += k[i] + 'A' - 'a';
}
}
string encryption(string t)
{
string output;
for (int i = 0, j = 0; i <= t.length(); ++i)
{
char c = t[i];
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
else if (c < 'A' || c > 'Z')
continue;
output += (c + k[j] - 2 * 'A') % 26 + 'A'; //added 'A' to bring it in range of
ASCII alphabet [ 65-90 | A-Z ]
j = (j + 1) % k.length();
}
return output;
}
string decryption(string t)
{
string output;
for (int i = 0, j = 0; i <= t.length(); ++i)
{
char c = t[i];
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
else if (c < 'A' || c > 'Z')
continue;
output += (c - k[j] + 26) % 26 + 'A';//added 'A' to bring it in range of
ASCII alphabet [ 65-90 | A-Z ]
j = (j + 1) % k.length();
}
return output;
}
};
string encryption(string m)
{
int a = 1, b = 2;
cout << "enter 1 key " << endl;
cin >> a;
cout << "enter 2 key " << endl;
cin >> b;
//Cipher Text initially empty
string c = "";
for (int i = 0; i < m.length(); i++)
{
// Avoid space to be encrypted
if (m[i] != ' ')
// added 'A' to bring it in range of ASCII alphabet [ 65-90 | A-Z ]
c = c + (char)((((a * (m[i] - 'A')) + b) % 26) + 'A');
else
//else append space character
c += m[i];
}
return c;
};
int findIndexAK(char ch)
{
int x;
for (int i = 0; i < 36; i++)
{
if (cip[i] == ch)
{
x = i;
i = 36;
}
}
return x;
}
void selectiontable(string k, string s)
{
int i, l = 0, x;
cout << "----key select from these words----"<<endl;
for (i = 0; i < 10; i++)
{
cip[l] = i + 48;
cout << cip[l];
l++;
}
cout <<" "<< endl;
for (i = 0; i < 26; i++)
{
cip[l] = i + 97;
cout << cip[l];
l++;
}
cout << " " << endl;
cout << endl;
cout << "************Key Code : " ;
for (i = 0; i < s.size(); i++)
{
x = findIndexAK(k[i]);
keyAK[i] = x;
cout << k[i];
}
cout << endl;
}
int EncryptAK(string s, string k)
{
int i, l = 0, x, y = 0;
for (i = 0; i < s.size(); i++)
{
if ((s[i] > 47 && s[i] < 58) || (s[i] > 96 && s[i] < 123))
{
x = findIndexAK(s[i]);
enc[i] = cip[(keyAK[y] + x) % 36];
y++;
if (y > k.size())
{
y = 0;
}
}
cout << enc[i];
}
return i;
}
void DecryptAK(char s[], string k, int j)
{
int i, l = 0, x, z, y = 0;
for (i = 0; i < j; i++)
{
if ((s[i] > 47 && s[i] < 58) || (s[i] > 96 && s[i] < 123))
{
x = findIndexAK(s[i]);
z = x - keyAK[y];
if (z < 0)
{
z = 36 + z;
}
decy[i] = cip[z];
y++;
if (y > k.size())
{
y = 0;
}
}
cout << decy[i];
}
return;
}
int main()
{
string s, k;
string UserWord, Enc, Dec, Plantext, Codetext;
int EncDecNumber, Cipher, key,number;
do {
cout << " Enter Cipher U want to use" << endl;
cout << "1: Ceaser Cipher n2: PlayFair Ciphern3: Affine n4: AutoKey Cipher
n5: Vigener " << endl;
cin >> Cipher;
if (Cipher == 1)
{
char msg[100];
cout << "Ceaser Cipher" << endl;
cout << "Enter the message:n";
cin >> msg;
//cin.getline(msg, 100); //take the message as input
int i, j, length, choice, key;
cout << "Enter key: ";
cin >> key; //take the key as input
length = strlen(msg);
cout << "Enter your choice n1. Encryption n2. Decryption n";
cin >> choice;
if (choice == 1) //for encryption
{
char ch;
for (int i = 0; msg[i] != '0'; ++i)
{
ch = msg[i];
//encrypt for lowercase letter
if (ch >= 'a' && ch <= 'z')
{
ch = ch + key;
if (ch > 'z') {
ch = ch - 'z' + 'a' - 1;
}
msg[i] = ch;
}
//encrypt for uppercase letter
else if (ch >= 'A' && ch <= 'Z')
{
ch = ch + key;
if (ch > 'Z')
{
ch = ch - 'Z' + 'A' - 1;
}
msg[i] = ch;
}
}
cout<<"Encrypted message: “<< msg<<endl;
}
else if (choice == 2) { //for decryption
char ch;
for (int i = 0; msg[i] != '0'; ++i) {
ch = msg[i];
//decrypt for lowercase letter
if (ch >= 'a' && ch <= 'z') {
ch = ch - key;
if (ch < 'a') {
ch = ch + 'z' - 'a' + 1;
}
msg[i] = ch;
}
//decrypt for uppercase letter
else if (ch >= 'A' && ch <= 'Z') {
ch = ch - key;
if (ch < 'A') {
ch = ch + 'Z' - 'A' + 1;
}
msg[i] = ch;
}
}
cout << "Decrypted message: " << msg;
}
else
{
cout << "Match NOT Found" << endl;
}
}
else if (Cipher == 2)
{
cout << "PlayFair Cipher Alphabet" << endl;
cout << " Enter any string " << endl;
cin >> UserWord;
cout << "What do u Wantn1: Encryption norn2: DecryptionnPress
number" << endl;
cin >> EncDecNumber;
if (EncDecNumber == 1)
{
cout << "PlayFair Cipher Alphabet Encrypted data" << endl;
}
else if (EncDecNumber == 2)
{
cout << "PlayFair Cipher Decrypted data" << endl;
}
else
{
cout << "Match NOT Found" << endl;
}
}
else if (Cipher == 3)
{
cout << "Affine" << endl;
cout << " Enter any string " << endl;
cin >> UserWord;
string c = encryption(UserWord);
cout << "Encrypted Message is : " << c << endl;
}
else if (Cipher == 4)
{
cout << "Autokey Cipher " << endl;
cout << " Enter any string " << endl;
cin >> UserWord;
cout << "What do u Wantn1: Encryption norn2: DecryptionnPress
number" << endl;
cin >> EncDecNumber;
cout << "Enter the Key : " << endl;
cin >> k;
int i, j{}, f = 0;
for (i = 0; i < UserWord.size(); i++)
{
if ((UserWord[i] > 47 && UserWord[i] < 58) || (UserWord[i] > 96
&& UserWord[i] < 123))
{
k.append(UserWord, i, 1);
}
}
selectiontable(k, UserWord);
if (EncDecNumber == 1)
{
cout << "Autokey Cipher Encrypted data" << endl;
cout << " your data : " << UserWord;
cout << "nEncrypted Message : ";
j = EncryptAK(UserWord, k);
}
else if (EncDecNumber == 2)
{
cout << "Autokey Cipher Decrypted data" << endl;
cout << " your data : " << UserWord;
cout << "nDecrypted Message : ";
DecryptAK(enc, k, j);
}
else
{
cout << "Match NOT Found" << endl;
}
}
else if (Cipher == 5)
{
string qi;
cout << " enter key" << endl;
cin >> qi;
Vig v(qi);
cout << "Keyless Vigener " << endl;
cout << " Enter any string " << endl;
cin >> UserWord;
cout << "What do u Wantn1: Encryption norn2: DecryptionnPress
number" << endl;
cin >> EncDecNumber;
if (EncDecNumber == 1)
{
cout << "Vigener Encrypted data" << endl;
string encrypt = v.encryption(UserWord);
cout << "Original Message: " << UserWord << endl;
cout << "Encrypted Message: " << encrypt << endl;
}
else if (EncDecNumber == 2)
{
cout << "Vigener Decrypted data" << endl;
string decrypt = v.decryption(UserWord);
cout << "Decrypted Message: " << decrypt << endl;
}
else
{
cout << "Match NOT Found" << endl;
}
}
cout << " enter 0 when u eixt" << endl;
}while (Cipher != 0);
system("pause");
}

More Related Content

What's hot

C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 
A survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic EncryptionA survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic Encryption
iosrjce
 
Binomial heap
Binomial heapBinomial heap
Binomial heap
Kalpana Vijayaraghavan
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
Farhan Ab Rahman
 
Network security
Network securityNetwork security
Network security
babyangle
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Dimitrios Platis
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
Farhan Ab Rahman
 
Lambda expressions in C++
Lambda expressions in C++Lambda expressions in C++
Lambda expressions in C++
Dimitrios Platis
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
Farhan Ab Rahman
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
Farhan Ab Rahman
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
Certified Pseudonym Colligated with Master Secret Key
Certified Pseudonym Colligated with Master Secret KeyCertified Pseudonym Colligated with Master Secret Key
Certified Pseudonym Colligated with Master Secret KeyVijay Pasupathinathan, PhD
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
PVS-Studio
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
Arsh Vishwakarma
 
[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place종빈 오
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
aleks-f
 
Bank management system project in c++ with graphics
Bank management system project in c++ with graphicsBank management system project in c++ with graphics
Bank management system project in c++ with graphics
Vtech Academy of Computers
 

What's hot (20)

C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
A survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic EncryptionA survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic Encryption
 
Binomial heap
Binomial heapBinomial heap
Binomial heap
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Network security
Network securityNetwork security
Network security
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
Lambda expressions in C++
Lambda expressions in C++Lambda expressions in C++
Lambda expressions in C++
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Certified Pseudonym Colligated with Master Secret Key
Certified Pseudonym Colligated with Master Secret KeyCertified Pseudonym Colligated with Master Secret Key
Certified Pseudonym Colligated with Master Secret Key
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
 
Bank management system project in c++ with graphics
Bank management system project in c++ with graphicsBank management system project in c++ with graphics
Bank management system project in c++ with graphics
 

Similar to Asssignment2

i need to write a return type function that takes information about th.docx
i need to write a return type function that takes information about th.docxi need to write a return type function that takes information about th.docx
i need to write a return type function that takes information about th.docx
hendriciraida
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
SWATIKUMARIRA2111030
 
include.docx
include.docxinclude.docx
include.docx
NhiPtaa
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul Patel
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
i want to add to this c++ code a condition so that you can only chose.docx
i want to add to this c++ code a condition so that you can only chose.docxi want to add to this c++ code a condition so that you can only chose.docx
i want to add to this c++ code a condition so that you can only chose.docx
hendriciraida
 
IT6712 lab manual
IT6712 lab manualIT6712 lab manual
IT6712 lab manual
Madhu Amarnath
 
Cpp programs
Cpp programsCpp programs
Cpp programs
harman kaur
 
Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)MountAbuRohini
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
Yung-Yu Chen
 
i need to modify this c++ so when the user enter services thats not an.docx
i need to modify this c++ so when the user enter services thats not an.docxi need to modify this c++ so when the user enter services thats not an.docx
i need to modify this c++ so when the user enter services thats not an.docx
hendriciraida
 
#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdf
APMRETAIL
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
FrankDin1
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdf
gaurav444u
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 

Similar to Asssignment2 (20)

i need to write a return type function that takes information about th.docx
i need to write a return type function that takes information about th.docxi need to write a return type function that takes information about th.docx
i need to write a return type function that takes information about th.docx
 
UDP.yash
UDP.yashUDP.yash
UDP.yash
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
include.docx
include.docxinclude.docx
include.docx
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
i want to add to this c++ code a condition so that you can only chose.docx
i want to add to this c++ code a condition so that you can only chose.docxi want to add to this c++ code a condition so that you can only chose.docx
i want to add to this c++ code a condition so that you can only chose.docx
 
IT6712 lab manual
IT6712 lab manualIT6712 lab manual
IT6712 lab manual
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
i need to modify this c++ so when the user enter services thats not an.docx
i need to modify this c++ so when the user enter services thats not an.docxi need to modify this c++ so when the user enter services thats not an.docx
i need to modify this c++ so when the user enter services thats not an.docx
 
#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdf
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdf
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 

Recently uploaded

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 

Asssignment2

  • 1. JAWARIYA JAWAAD 393/BSIT/F19 ANAM SALEEM 398/BSIT/F19 ASSIGNMENT 2 ScreenShots:
  • 2. Code: // security.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include<string> using namespace std; char MsgAutoKey[1000], cip[36], enc[1000], decy[1000]; int keyAK[1000]; class Vig { public: string k;
  • 3. Vig(string k) { for (int i = 0; i <= k.size(); ++i) { if (k[i] >= 'A' && k[i] <= 'Z') this->k += k[i]; else if (k[i] >= 'a' && k[i] <= 'z') this->k += k[i] + 'A' - 'a'; } } string encryption(string t) { string output; for (int i = 0, j = 0; i <= t.length(); ++i) { char c = t[i]; if (c >= 'a' && c <= 'z') c += 'A' - 'a'; else if (c < 'A' || c > 'Z') continue; output += (c + k[j] - 2 * 'A') % 26 + 'A'; //added 'A' to bring it in range of ASCII alphabet [ 65-90 | A-Z ] j = (j + 1) % k.length(); } return output; } string decryption(string t) { string output; for (int i = 0, j = 0; i <= t.length(); ++i) { char c = t[i]; if (c >= 'a' && c <= 'z') c += 'A' - 'a'; else if (c < 'A' || c > 'Z') continue; output += (c - k[j] + 26) % 26 + 'A';//added 'A' to bring it in range of ASCII alphabet [ 65-90 | A-Z ] j = (j + 1) % k.length(); } return output; } }; string encryption(string m) { int a = 1, b = 2; cout << "enter 1 key " << endl; cin >> a; cout << "enter 2 key " << endl;
  • 4. cin >> b; //Cipher Text initially empty string c = ""; for (int i = 0; i < m.length(); i++) { // Avoid space to be encrypted if (m[i] != ' ') // added 'A' to bring it in range of ASCII alphabet [ 65-90 | A-Z ] c = c + (char)((((a * (m[i] - 'A')) + b) % 26) + 'A'); else //else append space character c += m[i]; } return c; }; int findIndexAK(char ch) { int x; for (int i = 0; i < 36; i++) { if (cip[i] == ch) { x = i; i = 36; } } return x; } void selectiontable(string k, string s) { int i, l = 0, x; cout << "----key select from these words----"<<endl; for (i = 0; i < 10; i++) { cip[l] = i + 48; cout << cip[l]; l++; } cout <<" "<< endl; for (i = 0; i < 26; i++) { cip[l] = i + 97; cout << cip[l]; l++; } cout << " " << endl; cout << endl;
  • 5. cout << "************Key Code : " ; for (i = 0; i < s.size(); i++) { x = findIndexAK(k[i]); keyAK[i] = x; cout << k[i]; } cout << endl; } int EncryptAK(string s, string k) { int i, l = 0, x, y = 0; for (i = 0; i < s.size(); i++) { if ((s[i] > 47 && s[i] < 58) || (s[i] > 96 && s[i] < 123)) { x = findIndexAK(s[i]); enc[i] = cip[(keyAK[y] + x) % 36]; y++; if (y > k.size()) { y = 0; } } cout << enc[i]; } return i; } void DecryptAK(char s[], string k, int j) { int i, l = 0, x, z, y = 0; for (i = 0; i < j; i++) { if ((s[i] > 47 && s[i] < 58) || (s[i] > 96 && s[i] < 123)) { x = findIndexAK(s[i]); z = x - keyAK[y]; if (z < 0) { z = 36 + z; } decy[i] = cip[z]; y++; if (y > k.size())
  • 6. { y = 0; } } cout << decy[i]; } return; } int main() { string s, k; string UserWord, Enc, Dec, Plantext, Codetext; int EncDecNumber, Cipher, key,number; do { cout << " Enter Cipher U want to use" << endl; cout << "1: Ceaser Cipher n2: PlayFair Ciphern3: Affine n4: AutoKey Cipher n5: Vigener " << endl; cin >> Cipher; if (Cipher == 1) { char msg[100]; cout << "Ceaser Cipher" << endl; cout << "Enter the message:n"; cin >> msg; //cin.getline(msg, 100); //take the message as input int i, j, length, choice, key; cout << "Enter key: "; cin >> key; //take the key as input length = strlen(msg); cout << "Enter your choice n1. Encryption n2. Decryption n"; cin >> choice; if (choice == 1) //for encryption { char ch; for (int i = 0; msg[i] != '0'; ++i) { ch = msg[i]; //encrypt for lowercase letter if (ch >= 'a' && ch <= 'z') { ch = ch + key; if (ch > 'z') { ch = ch - 'z' + 'a' - 1; } msg[i] = ch; } //encrypt for uppercase letter
  • 7. else if (ch >= 'A' && ch <= 'Z') { ch = ch + key; if (ch > 'Z') { ch = ch - 'Z' + 'A' - 1; } msg[i] = ch; } } cout<<"Encrypted message: “<< msg<<endl; } else if (choice == 2) { //for decryption char ch; for (int i = 0; msg[i] != '0'; ++i) { ch = msg[i]; //decrypt for lowercase letter if (ch >= 'a' && ch <= 'z') { ch = ch - key; if (ch < 'a') { ch = ch + 'z' - 'a' + 1; } msg[i] = ch; } //decrypt for uppercase letter else if (ch >= 'A' && ch <= 'Z') { ch = ch - key; if (ch < 'A') { ch = ch + 'Z' - 'A' + 1; } msg[i] = ch; } } cout << "Decrypted message: " << msg; } else { cout << "Match NOT Found" << endl; } } else if (Cipher == 2) { cout << "PlayFair Cipher Alphabet" << endl; cout << " Enter any string " << endl; cin >> UserWord; cout << "What do u Wantn1: Encryption norn2: DecryptionnPress number" << endl; cin >> EncDecNumber;
  • 8. if (EncDecNumber == 1) { cout << "PlayFair Cipher Alphabet Encrypted data" << endl; } else if (EncDecNumber == 2) { cout << "PlayFair Cipher Decrypted data" << endl; } else { cout << "Match NOT Found" << endl; } } else if (Cipher == 3) { cout << "Affine" << endl; cout << " Enter any string " << endl; cin >> UserWord; string c = encryption(UserWord); cout << "Encrypted Message is : " << c << endl; } else if (Cipher == 4) { cout << "Autokey Cipher " << endl; cout << " Enter any string " << endl; cin >> UserWord; cout << "What do u Wantn1: Encryption norn2: DecryptionnPress number" << endl; cin >> EncDecNumber; cout << "Enter the Key : " << endl; cin >> k; int i, j{}, f = 0; for (i = 0; i < UserWord.size(); i++) { if ((UserWord[i] > 47 && UserWord[i] < 58) || (UserWord[i] > 96 && UserWord[i] < 123)) { k.append(UserWord, i, 1); } } selectiontable(k, UserWord); if (EncDecNumber == 1) { cout << "Autokey Cipher Encrypted data" << endl; cout << " your data : " << UserWord; cout << "nEncrypted Message : "; j = EncryptAK(UserWord, k);
  • 9. } else if (EncDecNumber == 2) { cout << "Autokey Cipher Decrypted data" << endl; cout << " your data : " << UserWord; cout << "nDecrypted Message : "; DecryptAK(enc, k, j); } else { cout << "Match NOT Found" << endl; } } else if (Cipher == 5) { string qi; cout << " enter key" << endl; cin >> qi; Vig v(qi); cout << "Keyless Vigener " << endl; cout << " Enter any string " << endl; cin >> UserWord; cout << "What do u Wantn1: Encryption norn2: DecryptionnPress number" << endl; cin >> EncDecNumber; if (EncDecNumber == 1) { cout << "Vigener Encrypted data" << endl; string encrypt = v.encryption(UserWord); cout << "Original Message: " << UserWord << endl; cout << "Encrypted Message: " << encrypt << endl; } else if (EncDecNumber == 2) { cout << "Vigener Decrypted data" << endl; string decrypt = v.decryption(UserWord); cout << "Decrypted Message: " << decrypt << endl; } else { cout << "Match NOT Found" << endl; } } cout << " enter 0 when u eixt" << endl; }while (Cipher != 0); system("pause"); }