Pure Programmer
Blue Matrix


Cluster Map

Project: Vigenère Cipher

By using interwoven [[Caesar Cipher]]s we can create a more complex polyalphabetic substitution called a [[Vigenère Cipher]]. Write a filter program that encrypts or decrypts text using a Vigenère Cipher. The alphabet to use should be the 95 ASCII printable characters.

The program should accept two command line arguments. The first is the password to use to set up the interwoven ciphers and the second is the encrypt/decrypt mode. If the second argument is "e", the program should take in clear (unencrypted) text on the standard input and write cipher (encrypted) text on the standard output. If the second argument is "d", the program should take in cipher (encrypted) text on the standard input and write clear (unencrypted) text on the standard output.

What is the weakness of this cipher? Is there an input pattern that reveals the password?

Output
$ rustc VigenereCipher.rs error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:33:5 | 33 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> VigenereCipher.rs:35:3 | 35 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::process::exit; | error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:37:28 | 37 | let mut password:String = args[1]; | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:38:26 | 38 | let mut encrypt:bool = (args[2] == "e".to_string()); | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | warning: unnecessary parentheses around assigned value --> VigenereCipher.rs:38:25 | 38 | let mut encrypt:bool = (args[2] == "e".to_string()); | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 38 - let mut encrypt:bool = (args[2] == "e".to_string()); 38 + let mut encrypt:bool = args[2] == "e".to_string(); | error[E0425]: cannot find function `strlen` in this scope --> VigenereCipher.rs:16:28 | 16 | static alphabetLen:isize = strlen(alphabet); | ^^^^^^ not found in this scope error[E0425]: cannot find function `find` in this scope --> VigenereCipher.rs:20:22 | 20 | let mut pos:isize = find(alphabet,cp); | ^^^^ not found in this scope error[E0433]: failed to resolve: use of undeclared crate or module `string` --> VigenereCipher.rs:21:12 | 21 | if pos != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `strlen` in this scope --> VigenereCipher.rs:40:30 | 40 | let mut passwordLen:isize = strlen(password); | ^^^^^^ not found in this scope error[E0425]: cannot find function `getcodepoint` in this scope --> VigenereCipher.rs:43:8 | 43 | while getcodepoint(c) { | ^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `find` in this scope --> VigenereCipher.rs:45:25 | 45 | let mut shift:isize = find(alphabet,pwdCP); | ^^^^ not found in this scope error[E0433]: failed to resolve: use of undeclared crate or module `string` --> VigenereCipher.rs:46:15 | 46 | if shift != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `putcodepoint` in this scope --> VigenereCipher.rs:49:3 | 49 | putcodepoint(c); | ^^^^^^^^^^^^ not found in this scope error: aborting due to 12 previous errors; 1 warning emitted Some errors have detailed explanations: E0425, E0433. For more information about an error, try `rustc --explain E0425`. $ rustc VigenereCipher.rs error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:33:5 | 33 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> VigenereCipher.rs:35:3 | 35 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::process::exit; | error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:37:28 | 37 | let mut password:String = args[1]; | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> VigenereCipher.rs:38:26 | 38 | let mut encrypt:bool = (args[2] == "e".to_string()); | ^^^^ not found in this scope | help: consider importing this function | 13 + use std::env::args; | warning: unnecessary parentheses around assigned value --> VigenereCipher.rs:38:25 | 38 | let mut encrypt:bool = (args[2] == "e".to_string()); | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 38 - let mut encrypt:bool = (args[2] == "e".to_string()); 38 + let mut encrypt:bool = args[2] == "e".to_string(); | error[E0425]: cannot find function `strlen` in this scope --> VigenereCipher.rs:16:28 | 16 | static alphabetLen:isize = strlen(alphabet); | ^^^^^^ not found in this scope error[E0425]: cannot find function `find` in this scope --> VigenereCipher.rs:20:22 | 20 | let mut pos:isize = find(alphabet,cp); | ^^^^ not found in this scope error[E0433]: failed to resolve: use of undeclared crate or module `string` --> VigenereCipher.rs:21:12 | 21 | if pos != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `strlen` in this scope --> VigenereCipher.rs:40:30 | 40 | let mut passwordLen:isize = strlen(password); | ^^^^^^ not found in this scope error[E0425]: cannot find function `getcodepoint` in this scope --> VigenereCipher.rs:43:8 | 43 | while getcodepoint(c) { | ^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `find` in this scope --> VigenereCipher.rs:45:25 | 45 | let mut shift:isize = find(alphabet,pwdCP); | ^^^^ not found in this scope error[E0433]: failed to resolve: use of undeclared crate or module `string` --> VigenereCipher.rs:46:15 | 46 | if shift != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `putcodepoint` in this scope --> VigenereCipher.rs:49:3 | 49 | putcodepoint(c); | ^^^^^^^^^^^^ not found in this scope error: aborting due to 12 previous errors; 1 warning emitted Some errors have detailed explanations: E0425, E0433. For more information about an error, try `rustc --explain E0425`.

Solution