Vigenère Cipher
Polyalphabetic substitution cipher using keyword. Invented by Giovan Battista Bellaso in 1553, misattributed to Blaise de Vigenère. More secure than Caesar, resists simple frequency analysis.
Visualization
Interactive visualization for Vigenère Cipher
Interactive visualization with step-by-step execution
Implementation
1function vigenereEncrypt(plaintext: string, keyword: string): string {
2 plaintext = plaintext.toUpperCase().replace(/[^A-Z]/g, '');
3 keyword = keyword.toUpperCase().replace(/[^A-Z]/g, '');
4
5 let result = '';
6 for (let i = 0; i < plaintext.length; i++) {
7 const p = plaintext.charCodeAt(i) - 65;
8 const k = keyword.charCodeAt(i % keyword.length) - 65;
9 result += String.fromCharCode(((p + k) % 26) + 65);
10 }
11
12 return result;
13}
14
15function vigenereDecrypt(ciphertext: string, keyword: string): string {
16 ciphertext = ciphertext.toUpperCase().replace(/[^A-Z]/g, '');
17 keyword = keyword.toUpperCase().replace(/[^A-Z]/g, '');
18
19 let result = '';
20 for (let i = 0; i < ciphertext.length; i++) {
21 const c = ciphertext.charCodeAt(i) - 65;
22 const k = keyword.charCodeAt(i % keyword.length) - 65;
23 result += String.fromCharCode(((c - k + 26) % 26) + 65);
24 }
25
26 return result;
27}Deep Dive
Theoretical Foundation
Uses keyword repeated to match text length. Each letter in keyword determines Caesar shift for corresponding plaintext letter. Different shifts make frequency analysis harder. Kasiski examination and Friedman test can break it.
Complexity
Time
O(n)
O(n)
O(n)
Space
O(n)
Applications
Industry Use
Historical diplomatic communications
Educational cryptography courses
Capture The Flag (CTF) competitions
Puzzle and mystery games
Understanding polyalphabetic principles
Basis for more advanced ciphers
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.