-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Sanderson
committed
Aug 23, 2014
0 parents
commit 9dbfe80
Showing
5 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target | ||
/Cargo.lock | ||
/*.iml | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "crypto" | ||
version = "0.0.1" | ||
authors = ["zofrex"] | ||
|
||
[[bin]] | ||
|
||
name = "hex_to_base64" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
pub fn hex_to_dec(hex: char) -> int { | ||
if hex >= '0' && hex <= '9' { | ||
hex as int - '0' as int | ||
} | ||
else if hex >= 'a' && hex <= 'f' { | ||
hex as int - 'a' as int + 10 | ||
} | ||
else { | ||
fail!("Character {} out of range", hex); | ||
} | ||
} | ||
|
||
#[test] | ||
fn all_hexes() { | ||
let hexes = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; | ||
for i in range(0u, hexes.len()) { | ||
assert_eq!(hex_to_dec(hexes[i]), i as int); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_fail] | ||
fn test_too_large() { | ||
hex_to_dec('g'); | ||
} | ||
|
||
#[test] | ||
#[should_fail] | ||
fn test_too_small() { | ||
hex_to_dec('/'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod hex; | ||
|
||
fn main() { | ||
println!("Output: {}", hex::hex_to_dec('0')); | ||
} |