Project: Caesar Cipher
The [[Caesar Cipher]] is one of the oldest and simplest encryption techniques known. Write a filter program that encrypts or decrypts text using a Caesar Cipher. It should only shift alphabetic characters taking into account that uppercase characters should shift to other uppercase characters and lowercase characters should shift to other lowercase characters.
The program should accept two command line arguments. The first is the shift amount (0-25) 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.
Output
$ rustc CaesarCipher1.rs
error: unknown format trait `s`
--> CaesarCipher1.rs:21:38
|
21 | println!("{}", format!("Syntax: {0:s} 0-{1:d} e|d", utils::program_name().expect("program name should not be empty!"), alphabetL...
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error: unknown format trait `d`
--> CaesarCipher1.rs:21:46
|
21 | println!("{}", format!("Syntax: {0:s} 0-{1:d} e|d", utils::program_name().expect("program name should not be empty!"), alphabetL...
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error[E0425]: cannot find value `args` in this scope
--> CaesarCipher1.rs:20:5
|
20 | 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
--> CaesarCipher1.rs:22:3
|
22 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
13 + use std::process::exit;
|
error[E0425]: cannot find value `Utils` in this scope
--> CaesarCipher1.rs:25:20
|
25 | let shift:isize = Utils.stoiWithDefault(args[1], 0);
| ^^^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> CaesarCipher1.rs:25:42
|
25 | let shift:isize = Utils.stoiWithDefault(args[1], 0);
| ^^^^ not found in this scope
|
help: consider importing this function
|
13 + use std::env::args;
|
error[E0425]: cannot find value `args` in this scope
--> CaesarCipher1.rs:26:21
|
26 | let encrypt:bool = args[2] == "e".to_string();
| ^^^^ not found in this scope
|
help: consider importing this function
|
13 + use std::env::args;
|
error[E0425]: cannot find function `strlen` in this scope
--> CaesarCipher1.rs:17:28
|
17 | static alphabetLen:isize = strlen(upperAlpha);
| ^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> CaesarCipher1.rs:29:8
|
29 | while getcodepoint(cp) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `islower` in this scope
--> CaesarCipher1.rs:31:6
|
31 | if islower(cp) {
| ^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> CaesarCipher1.rs:36:40
|
36 | let mut result:char = char::from_u32(cp);
| -------------- ^^ expected `u32`, found `i32`
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> /opt/local/libexec/rust/src/rustc-1.71.1-src/library/core/src/char/methods.rs:139:18
help: you can convert an `i32` to a `u32` and panic if the converted value doesn't fit
|
36 | let mut result:char = char::from_u32(cp.try_into().unwrap());
| ++++++++++++++++++++
error[E0308]: mismatched types
--> CaesarCipher1.rs:36:25
|
36 | let mut result:char = char::from_u32(cp);
| ---- ^^^^^^^^^^^^^^^^^^ expected `char`, found `Option<char>`
| |
| expected due to this
|
= note: expected type `char`
found enum `Option<char>`
error[E0425]: cannot find function `find` in this scope
--> CaesarCipher1.rs:37:23
|
37 | let mut pos:isize = find(alphabet,result);
| ^^^^ not found in this scope
error[E0425]: cannot find function `putchar` in this scope
--> CaesarCipher1.rs:47:3
|
47 | putchar(result);
| ^^^^^^^ not found in this scope
error: aborting due to 14 previous errors
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
Solution