SlideShare a Scribd company logo
CEASER & VIGENERE CIPHER IMPLEMENTATION
Name: SAFWAN HASHMI
Table of Contents
Ceaser Ciphers ................................................................................................................................. 1
1.1 Ceaser Ciphere...........................................................................................................1
1.2 Ceaser Cipher Algorithm........................................................................................... 1
1.3 Ceaser Cipher Screen Shots ......................................................................................2
Vigener Ciphers................................................................................................................................ 3
2.1 Vigener Ciphere.........................................................................................................3
2.2 Vigener Cipher Algorithm.........................................................................................4
2.3 Vigener Cipher Screen Shots ....................................................................................4
Fig 1.1 Ceaser Cipher Screenshot .......................................................................................2
Fig 1.2 Ceaser Cipher...........................................................................................................2
Fig 2.1 Vignere Screensshot ................................................................................................4
Fig 2.2 Vignere Cipher.........................................................................................................4
Ceaser Cipher
1.1 Ceaser Cipher
The Caesar cipher, also known as a shift cipher, is one of the simplest forms of
encryption. It is a substitution cipher where each letter in the original message
(called the plaintext) is replaced with a letter corresponding to a certain number
of letters up.
1.2 Algorithm
public static class Ceaser
{
public static string Encrypt(string plainText, int shift)
{
return CeaserAlgorithm(plainText, shift);
}
public static string Decrypt(string cipheredText, int shift)
{
return CeaserAlgorithm(cipheredText, shift * -1);
}
private static bool IsLetter(char letter)
{
return char.IsLetter(letter);
}
private static string CeaserAlgorithm(string text, int shift)
{
var buffer = text.ToCharArray();
for (var i = 0; i < buffer.Length; i++)
{
var letter = buffer[i];
if (!IsLetter(letter))
{
buffer[i] = ' ';
}
else
{
letter = (char)(letter + shift);
if (IsOverFlow(letter))
letter = (char)(letter - 26);
else if (IsUnderFlow(letter))
letter = (char)(letter + 26);
buffer[i] = letter;
}
}
return new string(buffer);
}
private static bool IsOverFlow(char letter)
{
return letter > 'z';
}
private static bool IsUnderFlow(char letter)
{
return letter < 'a';
}
}
1.3 Screen Shots
Fig. 1.1
Fig. 1.2
Vigenere Cipher
2.1 Vigenere Cipher
The Vigenere cipher is a method of encrypting alphabetic text by using a series
of different Caesar ciphers based on the letters of a keyword. It is a simple form
of polyalphabetic substitution.
2.2 Algorithm
public static class Vigenere
{
private static string Algorithm(string input, string key, bool encipher)
{
if (key.Any(t => !IsLetter(t)))
return null;
var result = string.Empty;
var nonAlphaCharCount = 0;
for (var i = 0; i < input.Length; ++i)
{
if (IsLetter(input[i]))
{
var offset = 'a';
if (IsUpperLetter(input[i]))
offset = 'A';
var keyIndex = (i - nonAlphaCharCount) % key.Length;
var k = (IsUpperLetter(input[i]) ? char.ToUpper(key[keyIndex]) :
char.ToLower(key[keyIndex])) - offset;
k = encipher ? k : -k;
var ch = (char)(Mod(input[i] + k - offset, 26) + offset);
result += ch;
}
else
{
result += input[i];
++nonAlphaCharCount;
}
}
return result;
}
private static bool IsUpperLetter(char c)
{
return char.IsUpper(c);
}
private static bool IsLetter(char letter)
{
return char.IsLetter(letter);
}
public static string Encrypt(string input, string key)
{
return Algorithm(input, key, true);
}
public static string Decrypt(string input, string key)
{
return Algorithm(input, key, false);
}
private static int Mod(int a, int b)
{
return (a % b + b) % b;
}
}
2.3 Screen Shots
Fig. 2.1
Fig. 2.2

More Related Content

More from Safwan Hashmi

Dark web
Dark webDark web
Dark web
Safwan Hashmi
 
Incident managment plan
Incident managment planIncident managment plan
Incident managment plan
Safwan Hashmi
 
Business continuity plan
Business continuity planBusiness continuity plan
Business continuity plan
Safwan Hashmi
 
Sql injection
Sql injectionSql injection
Sql injection
Safwan Hashmi
 
Soap xp-wg
Soap xp-wgSoap xp-wg
Soap xp-wg
Safwan Hashmi
 
Sql security
Sql securitySql security
Sql security
Safwan Hashmi
 
Database design
Database designDatabase design
Database design
Safwan Hashmi
 
Alpha beta prouning
Alpha beta prouningAlpha beta prouning
Alpha beta prouning
Safwan Hashmi
 
Color and color models
Color and color modelsColor and color models
Color and color models
Safwan Hashmi
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAP
Safwan Hashmi
 

More from Safwan Hashmi (15)

Dark web
Dark webDark web
Dark web
 
Incident managment plan
Incident managment planIncident managment plan
Incident managment plan
 
Business continuity plan
Business continuity planBusiness continuity plan
Business continuity plan
 
Sql injection
Sql injectionSql injection
Sql injection
 
Soap xp-wg
Soap xp-wgSoap xp-wg
Soap xp-wg
 
Sql security
Sql securitySql security
Sql security
 
Database design
Database designDatabase design
Database design
 
Alpha beta prouning
Alpha beta prouningAlpha beta prouning
Alpha beta prouning
 
Color and color models
Color and color modelsColor and color models
Color and color models
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAP
 
Democracy.s
Democracy.sDemocracy.s
Democracy.s
 
Democracy01
Democracy01Democracy01
Democracy01
 
Democracy.ppt
Democracy.pptDemocracy.ppt
Democracy.ppt
 
Calunization
CalunizationCalunization
Calunization
 
Development
DevelopmentDevelopment
Development
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

CEASER & VIGENERE CIPHER IMPLEMENTATION

  • 1. CEASER & VIGENERE CIPHER IMPLEMENTATION Name: SAFWAN HASHMI
  • 2. Table of Contents Ceaser Ciphers ................................................................................................................................. 1 1.1 Ceaser Ciphere...........................................................................................................1 1.2 Ceaser Cipher Algorithm........................................................................................... 1 1.3 Ceaser Cipher Screen Shots ......................................................................................2 Vigener Ciphers................................................................................................................................ 3 2.1 Vigener Ciphere.........................................................................................................3 2.2 Vigener Cipher Algorithm.........................................................................................4 2.3 Vigener Cipher Screen Shots ....................................................................................4
  • 3. Fig 1.1 Ceaser Cipher Screenshot .......................................................................................2 Fig 1.2 Ceaser Cipher...........................................................................................................2 Fig 2.1 Vignere Screensshot ................................................................................................4 Fig 2.2 Vignere Cipher.........................................................................................................4
  • 4. Ceaser Cipher 1.1 Ceaser Cipher The Caesar cipher, also known as a shift cipher, is one of the simplest forms of encryption. It is a substitution cipher where each letter in the original message (called the plaintext) is replaced with a letter corresponding to a certain number of letters up. 1.2 Algorithm public static class Ceaser { public static string Encrypt(string plainText, int shift) { return CeaserAlgorithm(plainText, shift); } public static string Decrypt(string cipheredText, int shift) { return CeaserAlgorithm(cipheredText, shift * -1); } private static bool IsLetter(char letter) { return char.IsLetter(letter); } private static string CeaserAlgorithm(string text, int shift) { var buffer = text.ToCharArray(); for (var i = 0; i < buffer.Length; i++) { var letter = buffer[i]; if (!IsLetter(letter)) { buffer[i] = ' '; } else { letter = (char)(letter + shift); if (IsOverFlow(letter)) letter = (char)(letter - 26); else if (IsUnderFlow(letter)) letter = (char)(letter + 26); buffer[i] = letter; } } return new string(buffer); } private static bool IsOverFlow(char letter) { return letter > 'z'; } private static bool IsUnderFlow(char letter) { return letter < 'a'; } }
  • 5. 1.3 Screen Shots Fig. 1.1 Fig. 1.2
  • 6. Vigenere Cipher 2.1 Vigenere Cipher The Vigenere cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution. 2.2 Algorithm public static class Vigenere { private static string Algorithm(string input, string key, bool encipher) { if (key.Any(t => !IsLetter(t))) return null; var result = string.Empty; var nonAlphaCharCount = 0; for (var i = 0; i < input.Length; ++i) { if (IsLetter(input[i])) { var offset = 'a'; if (IsUpperLetter(input[i])) offset = 'A'; var keyIndex = (i - nonAlphaCharCount) % key.Length; var k = (IsUpperLetter(input[i]) ? char.ToUpper(key[keyIndex]) : char.ToLower(key[keyIndex])) - offset; k = encipher ? k : -k; var ch = (char)(Mod(input[i] + k - offset, 26) + offset); result += ch; } else { result += input[i]; ++nonAlphaCharCount; } } return result; } private static bool IsUpperLetter(char c) { return char.IsUpper(c); } private static bool IsLetter(char letter) { return char.IsLetter(letter); } public static string Encrypt(string input, string key) { return Algorithm(input, key, true); } public static string Decrypt(string input, string key) { return Algorithm(input, key, false); } private static int Mod(int a, int b) { return (a % b + b) % b; } }
  • 7. 2.3 Screen Shots Fig. 2.1 Fig. 2.2