File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -83,5 +83,17 @@ const PC2 : [u8; 48] =
83
83
84
84
85
85
pub fn key_kn_from_pair ( left : i64 , right : i64 ) -> i64 {
86
- 0
86
+ let combined = ( ( left << 28 ) | right) << 8 ;
87
+ let mut encrypted_key = 0i64 ;
88
+ for idx in 0 ..48 {
89
+ let combined_bit_at_position = ( combined >> ( 64 - PC2 [ idx] ) ) & 1 ;
90
+ encrypted_key = encrypted_key << 1 ;
91
+ encrypted_key = encrypted_key | combined_bit_at_position;
92
+ }
93
+ encrypted_key
94
+ }
95
+
96
+
97
+ pub fn convert_pairs_to_encrypted_48_bit_keys ( pairs : Vec < ( i64 , i64 ) > ) -> Vec < i64 > {
98
+ Vec :: new ( )
87
99
}
Original file line number Diff line number Diff line change @@ -94,9 +94,18 @@ fn generate_key_plus_based_on_pc1_table() {
94
94
}
95
95
96
96
#[ test]
97
- fn creating_key_based_on_paris_and_PC2_table ( ) {
97
+ fn creating_key_based_on_pairs_and_PC2_table ( ) {
98
98
let left = 0b1110000110011001010101011111 ;
99
99
let right = 0b1010101011001100111100011110 ;
100
100
let expected_key = 0b000110110000001011101111111111000111000001110010 ;
101
101
assert_eq ! ( expected_key, key_kn_from_pair( left, right) ) ;
102
102
}
103
+
104
+
105
+ #[ test]
106
+ fn creating_48_bit_key_based_on_maximum_pairs ( ) {
107
+ let left = 0b1111_1111_1111_1111_1111_1111_1111 ;
108
+ let right = 0b1111_1111_1111_1111_1111_1111_1111 ;
109
+ let expected = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111 ;
110
+ assert_eq ! ( expected, key_kn_from_pair( left, right) ) ;
111
+ }
You can’t perform that action at this time.
0 commit comments