1
1
/// Encode an ASCII string into its location in a Polybius square.
2
2
/// Only alphabetical characters are encoded.
3
+ ///
4
+ /// # Arguments
5
+ ///
6
+ /// * `string` - The ASCII string to encode.
7
+ ///
8
+ /// # Returns
9
+ ///
10
+ /// The encoded string representing the location of each character in the Polybius square.
11
+ ///
12
+ /// # Examples
13
+ ///
14
+ /// ```rust
15
+ /// use rust_algorithms::ciphers::encode_ascii;
16
+ ///
17
+ /// let encoded = encode_ascii("This is a test");
18
+ ///
19
+ /// assert_eq!(encoded, "4423244324431144154344");
20
+ /// ```
3
21
pub fn encode_ascii ( string : & str ) -> String {
4
22
string
5
23
. chars ( )
@@ -38,6 +56,24 @@ pub fn encode_ascii(string: &str) -> String {
38
56
/// letters in a Polybius square.
39
57
///
40
58
/// Any invalid characters, or whitespace will be ignored.
59
+ ///
60
+ /// # Arguments
61
+ ///
62
+ /// * `string` - The string of integers to decode.
63
+ ///
64
+ /// # Returns
65
+ ///
66
+ /// The decoded string representing the corresponding letters in the Polybius square.
67
+ ///
68
+ /// # Examples
69
+ ///
70
+ /// ```rust
71
+ /// use rust_algorithms::ciphers::decode_ascii;
72
+ ///
73
+ /// let decoded = decode_ascii("44 23 24 43 24 43 11 44 15 43 44 ");
74
+ ///
75
+ /// assert_eq!(decoded, "THISISATEST");
76
+ /// ```
41
77
pub fn decode_ascii ( string : & str ) -> String {
42
78
string
43
79
. chars ( )
@@ -90,11 +126,6 @@ mod tests {
90
126
assert_eq ! ( encode_ascii( "" ) , "" ) ;
91
127
}
92
128
93
- #[ test]
94
- fn encode_valid_string ( ) {
95
- assert_eq ! ( encode_ascii( "This is a test" ) , "4423244324431144154344" ) ;
96
- }
97
-
98
129
#[ test]
99
130
fn encode_emoji ( ) {
100
131
assert_eq ! ( encode_ascii( "🙂" ) , "" ) ;
@@ -105,14 +136,6 @@ mod tests {
105
136
assert_eq ! ( decode_ascii( "" ) , "" ) ;
106
137
}
107
138
108
- #[ test]
109
- fn decode_valid_string ( ) {
110
- assert_eq ! (
111
- decode_ascii( "44 23 24 43 24 43 11 44 15 43 44 " ) ,
112
- "THISISATEST"
113
- ) ;
114
- }
115
-
116
139
#[ test]
117
140
fn decode_emoji ( ) {
118
141
assert_eq ! ( decode_ascii( "🙂" ) , "" ) ;
0 commit comments