Skip to content

Commit f6589bc

Browse files
committed
Added function to generate 48 bit keys
1 parent 2fd0e73 commit f6589bc

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,17 @@ const PC2 : [u8; 48] =
8383

8484

8585
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()
8799
}

src/main_tests.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,18 @@ fn generate_key_plus_based_on_pc1_table() {
9494
}
9595

9696
#[test]
97-
fn creating_key_based_on_paris_and_PC2_table() {
97+
fn creating_key_based_on_pairs_and_PC2_table() {
9898
let left = 0b1110000110011001010101011111;
9999
let right = 0b1010101011001100111100011110;
100100
let expected_key = 0b000110110000001011101111111111000111000001110010;
101101
assert_eq!(expected_key, key_kn_from_pair(left, right));
102102
}
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+
}

0 commit comments

Comments
 (0)