Security Assignment 1
Security Assignment 1
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.
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:
Keyword : AYUSH
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.
Encryption
The plaintext (P) and key (K) are added modulo 26.
Decryption
C++ CODE
#include<bits/stdc++.h>
int x = str.size();
if (x == i)
i = 0;
if (key.size() == str.size())
break;
key.push_back(key[i]);
return key;
}
// This function returns the encrypted text
string cipher_text;
x += 'A';
cipher_text.push_back(x);
return cipher_text;
string orig_text;
x += 'A';
orig_text.push_back(x);
return orig_text;
int main()
return 0;
Output
Ciphertext : ADGZUOHDMHBZHSSELWP
class GFG
10
11
int x = str.length();
12
13
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
25
26
27
{
28
String cipher_text="";
29
30
31
32
33
34
35
36
x += 'A';
37
38
cipher_text+=(char)(x);
39
}
40
return cipher_text;
41
42
43
44
45
46
47
String orig_text="";
48
49
50
51
{
52
53
int x = (cipher_text.charAt(i) -
54
55
56
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
65
66
67
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
80
81
82
83
84
85
86
87
String key = generateKey(str, keyword);
88
89
90
System.out.println("Ciphertext : "
91
+ cipher_text + "\n");
92
93
94
+ originalText(cipher_text, key));
95
96
97
98
99
Ciphertext : ARUNICVRGVVTVGGSLQJ