Anonymous user
Vigenère cipher: Difference between revisions
m
→{{header|Rust}}
Line 2,250:
=={{header|Rust}}==
{{works with|Rust|0.9}}
<lang Rust>fn uppercase_and_filter(in: &str) -> ~[u8] {▼
<lang Rust>use std::ascii::AsciiCast;
let mut result = ~[];▼
use std::str::from_utf8;
static a: u8 = 'a' as u8;
if char::is_ascii(c) {▼
// We know it's ascii, so just do the math directly▼
let
} else if char::is_uppercase(c) {▼
for b in input.bytes() {
result.push(c as u8);▼
if b.is_ascii()
let ascii
result.push((b + (A - a)))
}
}
}
}
fn vigenere(key: &str, text: &str, is_encoding: bool) -> ~str {
▲ const A: u8 = 'A' as u8;
▲ let text_bytes = uppercase_and_filter(text);
let mut i = 0;
for c
}
}
fn main() {
}</lang>▼
▲ io::println(fmt!("Text: %s", text));
▲ io::println(fmt!("Key: %s", key));
▲ let encoded = vigenere(key, text, true);
▲ io::println(fmt!("Code: %s", encoded));
▲ let decoded = vigenere(key, encoded, false);
▲ io::println(fmt!("Back: %s", decoded));
▲</lang>
=={{header|Scala}}==
Valid characters for messages: A through Z, zero, 1 to 9, and full-stop (.)
|