0% found this document useful (0 votes)
7 views

Security Assignment 1

security assignment 1

Uploaded by

King Of queens
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Security Assignment 1

security assignment 1

Uploaded by

King Of queens
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction

Cryptography, the science of encoding and decoding information to protect data, plays a crucial
role in securing communications in today's digital world. Its primary goal is to ensure
confidentiality, integrity, authenticity, and non-repudiation of data, providing a foundation for
secure electronic transactions, confidential communications, and safe data storage. By
transforming readable information into an unreadable format, cryptography prevents
unauthorized access and ensures that sensitive information remains secure even when transmitted
over insecure channels.

Various cryptographic techniques exist, ranging from classical methods to modern algorithms.
Classical methods, like the Caesar cipher and Atbash cipher, relied on simple letter substitutions
or reversals to obscure text. Modern cryptographic methods, however, use more complex
mathematical algorithms to achieve higher levels of security.

Among these classical ciphers, the Vigenere cipher stands out as a notable polyalphabetic
substitution cipher that incorporates a repeating keyword to encode plaintext. Unlike simple
substitution ciphers, the Vigenere cipher offers a higher degree of complexity by shifting letters
based on a sequence determined by a keyword. This approach made it more resilient to
traditional code-breaking techniques and was considered one of the strongest encryption methods
before.

In this assignment, we explore the Vigenere cipher, focusing on its key features and the
significance of key length in determining security strength. The implementation of this cipher in
a programming language provides a hands-on approach to understanding how polyalphabetic
substitution works and how key length can affect both security and performance. Additionally,
we will examine the relationship between key length and the running time of the encryption and
decryption processes to assess any trade-offs between security and efficiency.

The first part of the assignment is focused on implementing the Vigenère cipher in a
programming language, demonstrating how the repeating keyword modifies each letter based on
its position in the text. This implementation will allow us to encrypt and decrypt sample texts,
confirming the algorithm's effectiveness and accuracy. The second part involves investigating the
relationship between key length and security strength, examining how longer keys increase
resistance to cryptanalysis and brute-force attacks.

Finally, we will analyze the running time of the Vigenère cipher with different key lengths to
determine whether there is a significant performance difference. This analysis is essential for
understanding the practical implications of using the Vigenère cipher in real-world scenarios,
especially when high-security communication is required.
History

The very first well-documented description of a polyalphabetic cipher was by Leon Battista
Alberti around 1467 and used a metal cipher disk to switch between cipher alphabets. Alberti's
system only switched alphabets after several words, and switches were indicated by writing the
letter of the corresponding alphabet in the ciphertext. Later, Johannes Trithemius, in his
work Polygraphiae (which was completed in manuscript form in 1508 but first published in
1518), invented the tabula recta, a critical component of the Vigenère cipher. The Trithemius
cipher, however, provided a progressive, rather rigid and predictable system for switching
between cipher alphabets.

In 1586 Blaise de Vigenère published a type of polyalphabetic cipher called an autokey cipher –
because its key is based on the original plaintext – before the court of Henry III of France. The
cipher now known as the Vigenère cipher, however, is based on that originally described
by Giovan Battista Bellaso in his 1553 book La cifra del Sig. Giovan Battista Bellaso. He built
upon the tabula recta of Trithemius but added a repeating "countersign" (a key) to switch cipher
alphabets every letter.

Whereas Alberti and Trithemius used a fixed pattern of substitutions, Bellaso's scheme meant the
pattern of substitutions could be easily changed, simply by selecting a new key. Keys were
typically single words or short phrases, known to both parties in advance, or transmitted "out of
band" along with the message, Bellaso's method thus required strong security for only the key.
As it is relatively easy to secure a short key phrase, such as by a previous private conversation,
Bellaso's system was considerably more secure.

Note, however, as opposed to the modern Vigenère cipher, Bellaso's cipher didn't have 26
different "shifts" (different Caesar's ciphers) for every letter, instead having 13 shifts for pairs of
letters. In the 19th century, the invention of this cipher, essentially designed by Bellaso, was
misattributed to Vigenère. David Kahn, in his book, The Codebreakers lamented this
misattribution, saying that history had "ignored this important contribution and instead named a
regressive and elementary cipher for him Vigenère though he had nothing to do with it".

The Vigenère cipher gained a reputation for being exceptionally strong. Noted author and
mathematician Charles Lutwidge Dodgson (Lewis Carroll) called the Vigenère cipher
unbreakable in his 1868 piece "The Alphabet Cipher" in a children's magazine. In
1917, Scientific American described the Vigenère cipher as "impossible of translation". That
reputation was not deserved. Charles Babbage is known to have broken a variant of the cipher as
early as 1854 but did not publish his work. Kasiski entirely broke the cipher and published the
technique in the 19th century, but even in the 16th century, some skilled cryptanalysts could
occasionally break the cipher.
Figure 1: Cryptographic slide rule used as a calculation aid by the Swiss Army between
1914 and 1940.

The Vigenère cipher is simple enough to be a field cipher if it is used in conjunction with cipher
disks.The Confederate States of America, for example, used a brass cipher disk to implement the
Vigenère cipher during the American Civil War. The Confederacy's messages were far from
secret, and the Union regularly cracked its messages. Throughout the war, the Confederate
leadership primarily relied upon three key phrases: "Manchester Bluff", "Complete Victory" and,
as the war came to a close, "Come Retribution".

A Vigenère cipher with a completely random (and non-reusable) key which is as long as the
message becomes a one-time pad, a theoretically unbreakable cipher. Gilbert Vernam tried to
repair the broken cipher (creating the Vernam–Vigenère cipher in 1918), but the technology he
used was so cumbersome as to be impractical.
Vigenere cipher

The Vigenère cipher is a type of polyalphabetic substitution cipher that uses a repeating keyword
to encode plaintext into ciphertext. It's named after Blaise de Vigenère, a French cryptographer
who popularized the method in the 16th century. While earlier ciphers, like the Caesar cipher,
used a single shift value to transform text, the Vigenère cipher uses a sequence of shifts based on
a keyword, making it significantly more complex and secure.

Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple form


of polyalphabetic substitution. A polyalphabetic cipher is any cipher based on substitution, using
multiple substitution alphabets. The encryption of the original text is done using the Vigenère
square or Vigenère table.

The table consists of the alphabets written out 26 times in different rows, each alphabet shifted
cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar
Ciphers.

At different points in the encryption process, the cipher uses a different alphabet from one of the
rows. The alphabet used at each point depends on a repeating keyword.

Example:

Input : Plaintext : GEEKSFORGEEKS

Keyword : AYUSH

Output : Ciphertext : GCYCZFMLYLEIM

 For generating key, the given keyword is repeated in a circular manner until it matches
the length of the plain text.
 The keyword "AYUSH" generates the key "AYUSHAYUSHAYU"
 The plain text is then encrypted using the process explained below.

Encryption
The first letter of the plaintext, G is paired with A, the first letter of the key. So use row G and
column A of the Vigenère square, namely G. Similarly, for the second letter of the plaintext, the
second letter of the key is used, the letter at row E, and column Y is C. The rest of the plaintext is
enciphered in a similar fashion.
Figure 2: Table to encrypt – Geeks

Decryption

Decryption is performed by going to the row in the table corresponding to the key, finding the
position of the ciphertext letter in this row, and then using the column’s label as the plaintext.
For example, in row A (from AYUSH), the ciphertext G appears in column G, which is the first
plaintext letter. Next, we go to row Y (from AYUSH), locate the ciphertext C which is found in
column E, thus E is the second plaintext letter.

A more easy implementation could be to visualize Vigenère algebraically by converting [A-Z]


into numbers [0–25].

Encryption

The plaintext (P) and key (K) are added modulo 26.

Ei = (Pi + Ki) mod 26

Decryption

Di = (Ei - Ki) mod 26


Note: Di denotes the offset of the i-th character of the plaintext. Like offset of A is 0 and of B is
1 and so on.

Below is the implementation of the idea.

C++ CODE

// C++ code to implement Vigenere Cipher

#include<bits/stdc++.h>

using namespace std;

// This function generates the key in

// a cyclic manner until it's length isn't

// equal to the length of original text

string generateKey(string str, string key)

int x = str.size();

for (int i = 0; ; i++)

if (x == i)

i = 0;

if (key.size() == str.size())

break;

key.push_back(key[i]);

return key;

}
// This function returns the encrypted text

// generated with the help of the key

string cipherText(string str, string key)

string cipher_text;

for (int i = 0; i < str.size(); i++)

// converting in range 0-25

char x = (str[i] + key[i]) %26;

// convert into alphabets(ASCII)

x += 'A';

cipher_text.push_back(x);

return cipher_text;

// This function decrypts the encrypted text

// and returns the original text

string originalText(string cipher_text, string key)

string orig_text;

for (int i = 0 ; i < cipher_text.size(); i++)

// converting in range 0-25

char x = (cipher_text[i] - key[i] + 26) %26;


// convert into alphabets(ASCII)

x += 'A';

orig_text.push_back(x);

return orig_text;

// Driver program to test the above function

int main()

string str = " Instructor Zeynu M. ";

string keyword = "Secuity";

string key = generateKey(str, keyword);

string cipher_text = cipherText(str, key);

cout << "Ciphertext : "

<< cipher_text << "\n";

cout << "Original/Decrypted Text : "

<< originalText(cipher_text, key);

return 0;

Output

Ciphertext : ADGZUOHDMHBZHSSELWP

Original/Decrypted Text: Instructor Zeynu M.

Time Complexity : O(n), where n is the length of the string(here str).

Space Complexity : O(n), here n is the length of the string(here str).


// Java code to implement Vigenere Cipher

class GFG

// This function generates the key in

// a cyclic manner until it's length isi'nt

// equal to the length of original text

static String generateKey(String str, String key)

10

11

int x = str.length();

12

13

for (int i = 0; ; i++)

14

15
if (x == i)

16

i = 0;

17

if (key.length() == str.length())

18

break;

19

key+=(key.charAt(i));

20

21

return key;

22

23

24

// This function returns the encrypted text

25

// generated with the help of the key

26

static String cipherText(String str, String key)

27
{

28

String cipher_text="";

29

30

for (int i = 0; i < str.length(); i++)

31

32

// converting in range 0-25

33

int x = (str.charAt(i) + key.charAt(i)) %26;

34

35

// convert into alphabets(ASCII)

36

x += 'A';

37

38

cipher_text+=(char)(x);

39
}

40

return cipher_text;

41

42

43

// This function decrypts the encrypted text

44

// and returns the original text

45

static String originalText(String cipher_text, String key)

46

47

String orig_text="";

48

49

for (int i = 0 ; i < cipher_text.length() &&

50

i < key.length(); i++)

51
{

52

// converting in range 0-25

53

int x = (cipher_text.charAt(i) -

54

key.charAt(i) + 26) %26;

55

56

// convert into alphabets(ASCII)

57

x += 'A';

58

orig_text+=(char)(x);

59

60

return orig_text;

61

62

63
// This function will convert the lower case character to Upper case

64

static String LowerToUpper(String s)

65

66

StringBuffer str =new StringBuffer(s);

67

for(int i = 0; i < s.length(); i++)

68

69

if(Character.isLowerCase(s.charAt(i)))

70

71

str.setCharAt(i, Character.toUpperCase(s.charAt(i)));

72

73

74

s = str.toString();

75
return s;

76

77

78

// Driver code

79

public static void main(String[] args)

80

81

String Str = "Instructor Zeynu M.";

82

String Keyword = "Security";

83

84

String str = LowerToUpper(Str);

85

String keyword = LowerToUpper(Keyword);

86

87
String key = generateKey(str, keyword);

88

String cipher_text = cipherText(str, key);

89

90

System.out.println("Ciphertext : "

91

+ cipher_text + "\n");

92

93

System.out.println("Original/Decrypted Text : "

94

+ originalText(cipher_text, key));

95

96

97

98

// This code has been contributed by 29AjayKumar

99
Ciphertext : ARUNICVRGVVTVGGSLQJ

Original/Decrypted Text : INSTRUCTORTZEYNUTMH

You might also like