commit
f4b03eb5b1
4 changed files with 386 additions and 0 deletions
@ -0,0 +1 @@ |
|||
/target |
@ -0,0 +1,262 @@ |
|||
# This file is automatically @generated by Cargo. |
|||
# It is not intended for manual editing. |
|||
version = 3 |
|||
|
|||
[[package]] |
|||
name = "anstream" |
|||
version = "0.6.14" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" |
|||
dependencies = [ |
|||
"anstyle", |
|||
"anstyle-parse", |
|||
"anstyle-query", |
|||
"anstyle-wincon", |
|||
"colorchoice", |
|||
"is_terminal_polyfill", |
|||
"utf8parse", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "anstyle" |
|||
version = "1.0.7" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" |
|||
|
|||
[[package]] |
|||
name = "anstyle-parse" |
|||
version = "0.2.4" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" |
|||
dependencies = [ |
|||
"utf8parse", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "anstyle-query" |
|||
version = "1.1.0" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" |
|||
dependencies = [ |
|||
"windows-sys", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "anstyle-wincon" |
|||
version = "3.0.3" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" |
|||
dependencies = [ |
|||
"anstyle", |
|||
"windows-sys", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "autocfg" |
|||
version = "1.3.0" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" |
|||
|
|||
[[package]] |
|||
name = "clap" |
|||
version = "4.5.9" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" |
|||
dependencies = [ |
|||
"clap_builder", |
|||
"clap_derive", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "clap-num" |
|||
version = "1.1.1" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "0e063d263364859dc54fb064cedb7c122740cd4733644b14b176c097f51e8ab7" |
|||
dependencies = [ |
|||
"num-traits", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "clap_builder" |
|||
version = "4.5.9" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" |
|||
dependencies = [ |
|||
"anstream", |
|||
"anstyle", |
|||
"clap_lex", |
|||
"strsim", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "clap_derive" |
|||
version = "4.5.8" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" |
|||
dependencies = [ |
|||
"heck", |
|||
"proc-macro2", |
|||
"quote", |
|||
"syn", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "clap_lex" |
|||
version = "0.7.1" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" |
|||
|
|||
[[package]] |
|||
name = "colorchoice" |
|||
version = "1.0.1" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" |
|||
|
|||
[[package]] |
|||
name = "heck" |
|||
version = "0.5.0" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" |
|||
|
|||
[[package]] |
|||
name = "idea" |
|||
version = "0.1.0" |
|||
dependencies = [ |
|||
"clap", |
|||
"clap-num", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "is_terminal_polyfill" |
|||
version = "1.70.0" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" |
|||
|
|||
[[package]] |
|||
name = "num-traits" |
|||
version = "0.2.19" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" |
|||
dependencies = [ |
|||
"autocfg", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "proc-macro2" |
|||
version = "1.0.86" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" |
|||
dependencies = [ |
|||
"unicode-ident", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "quote" |
|||
version = "1.0.36" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" |
|||
dependencies = [ |
|||
"proc-macro2", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "strsim" |
|||
version = "0.11.1" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" |
|||
|
|||
[[package]] |
|||
name = "syn" |
|||
version = "2.0.71" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" |
|||
dependencies = [ |
|||
"proc-macro2", |
|||
"quote", |
|||
"unicode-ident", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "unicode-ident" |
|||
version = "1.0.12" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" |
|||
|
|||
[[package]] |
|||
name = "utf8parse" |
|||
version = "0.2.2" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" |
|||
|
|||
[[package]] |
|||
name = "windows-sys" |
|||
version = "0.52.0" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" |
|||
dependencies = [ |
|||
"windows-targets", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "windows-targets" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" |
|||
dependencies = [ |
|||
"windows_aarch64_gnullvm", |
|||
"windows_aarch64_msvc", |
|||
"windows_i686_gnu", |
|||
"windows_i686_gnullvm", |
|||
"windows_i686_msvc", |
|||
"windows_x86_64_gnu", |
|||
"windows_x86_64_gnullvm", |
|||
"windows_x86_64_msvc", |
|||
] |
|||
|
|||
[[package]] |
|||
name = "windows_aarch64_gnullvm" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" |
|||
|
|||
[[package]] |
|||
name = "windows_aarch64_msvc" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" |
|||
|
|||
[[package]] |
|||
name = "windows_i686_gnu" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" |
|||
|
|||
[[package]] |
|||
name = "windows_i686_gnullvm" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" |
|||
|
|||
[[package]] |
|||
name = "windows_i686_msvc" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" |
|||
|
|||
[[package]] |
|||
name = "windows_x86_64_gnu" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" |
|||
|
|||
[[package]] |
|||
name = "windows_x86_64_gnullvm" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" |
|||
|
|||
[[package]] |
|||
name = "windows_x86_64_msvc" |
|||
version = "0.52.6" |
|||
source = "registry+https://github.com/rust-lang/crates.io-index" |
|||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" |
@ -0,0 +1,8 @@ |
|||
[package] |
|||
name = "idea" |
|||
version = "0.2.0" |
|||
edition = "2021" |
|||
|
|||
[dependencies] |
|||
clap = { version = "4.0", features = ["derive"] } |
|||
clap-num = { version = "1.1" } |
@ -0,0 +1,115 @@ |
|||
// Angefangen: 13:30
|
|||
// bis: 16:20
|
|||
//
|
|||
|
|||
use clap::Parser; |
|||
use clap_num::maybe_hex; |
|||
|
|||
#[derive(Parser)] |
|||
struct Cli { |
|||
// The message to be encrypted
|
|||
#[arg(short = 'm', long = "message", value_parser=maybe_hex::<u64>, default_value_t = 0x42)] |
|||
message: u64, |
|||
// the key used for encryption/decryption
|
|||
#[arg(short = 'k', long = "key", value_parser=maybe_hex::<u128>, default_value_t = 123456789012345678901234567890)] |
|||
key: u128, |
|||
} |
|||
|
|||
struct Vr { |
|||
v1: u16, |
|||
v2: u16, |
|||
v3: u16, |
|||
v4: u16, |
|||
} |
|||
|
|||
impl Vr { |
|||
fn split(v: u64) -> Self { |
|||
let v4 = (v & 0xFFFF) as u16; |
|||
let v3 = ((v >> 16) & 0xFFFF) as u16; |
|||
let v2 = ((v >> 32) & 0xFFFF) as u16; |
|||
let v1 = ((v >> 48) & 0xFFFF) as u16; |
|||
Self{ v1: v1, v2: v2, v3: v3, v4: v4 } |
|||
} |
|||
|
|||
fn expand(&self) -> u64 { |
|||
(self.v1 as u64 * 2_u64.pow(48)) + (self.v2 as u64 * 2_u64.pow(32)) + (self.v3 as u64 * 2_u64.pow(16)) + self.v4 as u64 |
|||
} |
|||
} |
|||
|
|||
struct Keys { |
|||
z1: u16, z2: u16, z3: u16, z4: u16, z5: u16, z6: u16, |
|||
} |
|||
|
|||
|
|||
fn derive_keys(mut k: u128) -> Vec<Keys> { |
|||
let mut keys: Vec<Keys> = Vec::new(); |
|||
|
|||
let mut subkeys = Vec::new(); |
|||
while subkeys.len() < 52 { |
|||
subkeys.push((k & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 16) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 32) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 48) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 64) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 80) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 96) & 0xFFFF) as u16); |
|||
subkeys.push(((k >> 112) & 0xFFFF) as u16); |
|||
k = k.rotate_left(25);
|
|||
println!("key after shift {k}"); |
|||
} |
|||
let mut i = 0; |
|||
while keys.len() < 8 { |
|||
keys.push( |
|||
Keys{ z1: subkeys[0+i], z2: subkeys[1+i], z3: subkeys[2+i], z4: subkeys[3+i], z5: subkeys[4+i], z6: subkeys[5+i] }
|
|||
); |
|||
i = i+1; |
|||
} |
|||
keys.push( |
|||
Keys{ z1: subkeys[0+i], z2: subkeys[1+i], z3: subkeys[2+i], z4: subkeys[3+i], z5: 0, z6: 0 }
|
|||
); |
|||
keys |
|||
} |
|||
|
|||
fn add(a: u16, b: u16) -> u16 { |
|||
let (a, b, m) = (a as u32, b as u32, 0x10000 as u32); |
|||
((a * b) % m) as u16 |
|||
} |
|||
|
|||
fn mul(a: u16, b: u16) -> u16 { |
|||
let (a, b, m) = (a as u32, b as u32, 0x10001 as u32); |
|||
if a == 0 { |
|||
let a = 0x10000; |
|||
((a * b) % m) as u16 |
|||
} |
|||
else if b == 0 { |
|||
let b = 0x10000; |
|||
((a * b) % m) as u16 |
|||
} |
|||
else{ |
|||
((a * b) % m) as u16 |
|||
} |
|||
} |
|||
|
|||
fn idea_round() -> Vr { |
|||
Vr::split(80)
|
|||
} |
|||
|
|||
fn encrypt(k: u128, m: u64) -> u64 { |
|||
let xr = Vr::split(m); |
|||
assert_eq!(m, xr.expand()); |
|||
let round_keys = derive_keys(k); |
|||
mul(xr.v1, 0).into() |
|||
} |
|||
|
|||
fn main() { |
|||
println!("Welcome to your IDEA encryption tool!"); |
|||
|
|||
let args = Cli::parse(); |
|||
let key: u128 = args.key; |
|||
let message: u64 = args.message; |
|||
|
|||
println!("message: {:?}, key: {:?}", message, key); |
|||
|
|||
let cipher: u64 = encrypt(key, message); |
|||
println!("ciphertext: {:?}", cipher); |
|||
} |
Loading…
Reference in new issue