Project: Caesar Cipher (Modified)
Modify the [[Caesar Cipher]] program from project CaesarCipher1 to shift all ASCII printable characters not just the alphabetic characters. The allowable shift should now be 0-94. Upper and lowercase alphabetic characters do not need shift to their own type but can be shifted to any of the 95 printable ASCII characters.
Output
$ rustc CaesarCipher2.rs
error: unknown format trait `s`
--> CaesarCipher2.rs:20:38
|
20 | 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`
--> CaesarCipher2.rs:20:46
|
20 | 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
--> CaesarCipher2.rs:19:5
|
19 | 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
--> CaesarCipher2.rs:21:3
|
21 | 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
--> CaesarCipher2.rs:24:20
|
24 | let shift:isize = Utils.stoiWithDefault(args[1], 0);
| ^^^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> CaesarCipher2.rs:24:42
|
24 | 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
--> CaesarCipher2.rs:25:21
|
25 | 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
--> CaesarCipher2.rs:16:28
|
16 | static alphabetLen:isize = strlen(alphabet);
| ^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> CaesarCipher2.rs:28:8
|
28 | while getcodepoint(cp) {
| ^^^^^^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> CaesarCipher2.rs:29:40
|
29 | 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
|
29 | let mut result:char = char::from_u32(cp.try_into().unwrap());
| ++++++++++++++++++++
error[E0308]: mismatched types
--> CaesarCipher2.rs:29:25
|
29 | 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
--> CaesarCipher2.rs:30:23
|
30 | let mut pos:isize = find(alphabet,result);
| ^^^^ not found in this scope
error[E0425]: cannot find function `putchar` in this scope
--> CaesarCipher2.rs:40:3
|
40 | putchar(result);
| ^^^^^^^ not found in this scope
error: aborting due to 13 previous errors
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.