mirror of
https://github.com/kristoferssolo/cipher-workshop.git
synced 2025-12-20 11:04:38 +00:00
fix: wrong value in S8 box
This commit is contained in:
parent
6175305641
commit
2d59f4fb70
@ -22,18 +22,18 @@ impl Block64 {
|
||||
Self(u64::from_be_bytes(bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn to_le_bytes(self) -> [u8; 8] {
|
||||
self.0.to_le_bytes()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn to_be_bytes(self) -> [u8; 8] {
|
||||
self.0.to_be_bytes()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn to_le_bytes(self) -> [u8; 8] {
|
||||
self.0.to_le_bytes()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn split_lr(self) -> LR {
|
||||
@ -41,6 +41,12 @@ impl Block64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 8]> for Block64 {
|
||||
fn from(bytes: [u8; 8]) -> Self {
|
||||
Self::from_be_bytes(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Block64 {
|
||||
fn from(value: u64) -> Self {
|
||||
Self::new(value)
|
||||
@ -65,12 +71,12 @@ impl From<&Block64> for LR {
|
||||
|
||||
impl From<Block64> for Vec<u8> {
|
||||
fn from(value: Block64) -> Self {
|
||||
value.0.to_le_bytes().to_vec()
|
||||
value.0.to_be_bytes().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Block64> for Vec<u8> {
|
||||
fn from(value: &Block64) -> Self {
|
||||
value.0.to_le_bytes().to_vec()
|
||||
value.0.to_be_bytes().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ pub const S_BOXES: [[[u8; 16]; 4]; 8] = [
|
||||
],
|
||||
// S8
|
||||
[
|
||||
[13, 2, 8, 4, 6, 15, 11, 1, 19, 9, 3, 14, 5, 0, 12, 7],
|
||||
[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
|
||||
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
|
||||
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
|
||||
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11],
|
||||
|
||||
@ -58,6 +58,7 @@ where
|
||||
for subkey in subkeys {
|
||||
feistel(&mut lr, subkey);
|
||||
}
|
||||
lr.swap();
|
||||
lr.into()
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ impl AsRef<[u8]> for Key {
|
||||
|
||||
impl From<u64> for Key {
|
||||
fn from(key: u64) -> Self {
|
||||
Self(key.to_le_bytes())
|
||||
Self(key.to_be_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -116,7 +116,7 @@ fn encrypt_decrypt_roundtrip(
|
||||
) {
|
||||
let des = assert_ok!(Des::new(key), "Valid DES key");
|
||||
|
||||
let ciphertext = assert_ok!(des.encrypt(&plaintext.to_le_bytes()));
|
||||
let ciphertext = assert_ok!(des.encrypt(&plaintext.to_be_bytes()));
|
||||
let dectrypted = assert_ok!(des.decrypt(&ciphertext));
|
||||
let re_ciphertext = assert_ok!(des.encrypt(&dectrypted));
|
||||
|
||||
@ -126,7 +126,7 @@ fn encrypt_decrypt_roundtrip(
|
||||
|
||||
assert_eq!(
|
||||
ciphertext_u64, expected_ciphertext,
|
||||
"Encyption failed. Expected 0x{expected_ciphertext:016X}, got 0x{decrypted_u64:016X}"
|
||||
"Encyption failed. Expected 0x{expected_ciphertext:016X}, got 0x{ciphertext_u64:016X}"
|
||||
);
|
||||
assert_eq!(
|
||||
decrypted_u64, plaintext,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user