4
school/intro-crypto/uebung/03/u03/Cargo.lock
generated
Normal file
4
school/intro-crypto/uebung/03/u03/Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
||||
[[package]]
|
||||
name = "u03"
|
||||
version = "0.1.0"
|
||||
|
6
school/intro-crypto/uebung/03/u03/Cargo.toml
Normal file
6
school/intro-crypto/uebung/03/u03/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "u03"
|
||||
version = "0.1.0"
|
||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||
|
||||
[dependencies]
|
101
school/intro-crypto/uebung/03/u03/src/main.rs
Normal file
101
school/intro-crypto/uebung/03/u03/src/main.rs
Normal file
@ -0,0 +1,101 @@
|
||||
// use std::fs;
|
||||
struct Prng {
|
||||
a: u16,
|
||||
b: u16,
|
||||
c: u16,
|
||||
s0: u16,
|
||||
s1: u16,
|
||||
}
|
||||
|
||||
impl Iterator for Prng {
|
||||
type Item = u8;
|
||||
|
||||
fn next(&mut self) -> Option<u8> {
|
||||
let r = self.s0;
|
||||
self.s0 = self.s1;
|
||||
self.s1 = ((self.a * self.s1) % 257 + (self.b * r) % 257 + self.c) % 257;
|
||||
Some((r % 256) as u8)
|
||||
}
|
||||
}
|
||||
|
||||
impl Prng {
|
||||
fn new(s0: u16, s1: u16) -> Self {
|
||||
Self {
|
||||
s0: s0 % 257,
|
||||
s1: s1 % 257,
|
||||
a: 97,
|
||||
b: 212,
|
||||
c: 42,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// let c: &[u8] = &[0x4E, 0x7E, 0x3D, 0x88, 0x8E, 0x01, 0x0D, 0x84];
|
||||
// let p: &[u8] = &[0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F];
|
||||
// c.iter()
|
||||
// .zip(p.iter())
|
||||
// .map(|(c, p)| c ^ p)
|
||||
// .for_each(|k| print!("{:02X} ", k));
|
||||
|
||||
let c: &[u8] = &[
|
||||
0x4E, 0x7E, 0x3D, 0x88, 0x8E, 0x01, 0x0D, 0x84, 0xB8, 0x7E, 0xBF, 0x1A, 0x25, 0x37, 0xFA,
|
||||
0x4D, 0x89, 0x87, 0x91, 0xFA, 0x50, 0x51, 0xFC, 0x42, 0x7A, 0x9A, 0x6A, 0xE4,
|
||||
];
|
||||
let p = Prng::new(0x26, 0x0a);
|
||||
|
||||
c.into_iter()
|
||||
.zip(p)
|
||||
.map(|(c, k)| c ^ k)
|
||||
.map(|c| c as char)
|
||||
.for_each(|c| print!("{}", c));
|
||||
println!();
|
||||
|
||||
// let key: &[u8] = &[0xba, 0xad, 0xa5, 0x55, 0xc0, 0x00, 0x10, 0xff];
|
||||
// // let cipher: &[u8] = &[0x33, 0xfd, 0xeb, 0x12, 0xcd, 0x0a, 0x0a, 0xf5];
|
||||
// // let key: &[u8] = &[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
||||
// // cipher
|
||||
// // .iter()
|
||||
// // .zip(key.iter())
|
||||
// // .map(|(c, k)| c ^ k)
|
||||
// // .for_each(|p| print!("0x{:x} ", p));
|
||||
|
||||
// let args: Vec<_> = std::env::args().skip(1).collect();
|
||||
// let data = fs::read(&args[0]).expect("Cannot read");
|
||||
// let plain: Vec<_> = data
|
||||
// .into_iter()
|
||||
// .zip(key.into_iter().cycle())
|
||||
// .map(|(c, k)| c ^ k)
|
||||
// .collect();
|
||||
|
||||
// fs::write(&args[1], plain).expect("Cannot write");
|
||||
}
|
||||
|
||||
// fn main() {
|
||||
// let cipher: &[u8] = &[
|
||||
// 0xDC, 0x48, 0x13, 0x3B, 0x9C, 0x4C, 0x49, 0x80, 0xAC, 0xA7, 0xB9, 0x54, 0xF2, 0x7C, 0x2B,
|
||||
// 0x9E, 0xD5, 0xDF, 0x0D, 0x05, 0xB3, 0x1D, 0x4E, 0xF8,
|
||||
// ];
|
||||
// let key: &[u8] = &[
|
||||
// 0x98, 0x29, 0x60, 0x72, 0xF2, 0x38, 0x2C, 0xF2, 0xC2, 0xC2, 0xCD, 0x1D, 0x81, 0x08, 0x65,
|
||||
// 0xFB, 0xA0, 0xB3, 0x6C, 0x6B, 0xD7, 0x3C, 0x6F, 0xD9,
|
||||
// ];
|
||||
// cipher.iter().for_each(|c| print!("0x{:X} ", c));
|
||||
// println!();
|
||||
// key.iter().for_each(|c| print!("0x{:X} ", c));
|
||||
// println!();
|
||||
// cipher
|
||||
// .iter()
|
||||
// .zip(key.iter())
|
||||
// .map(|(c, k)| c ^ k)
|
||||
// .for_each(|p| print!("{:X} ", p));
|
||||
// println!();
|
||||
|
||||
// cipher
|
||||
// .iter()
|
||||
// .zip(key.iter())
|
||||
// .map(|(c, k)| c ^ k)
|
||||
// .map(|c| c as char)
|
||||
// .for_each(|p| print!("{} ", p));
|
||||
// println!();
|
||||
// }
|
@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":12819272735836075344,"outputs":{"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"1164083562126845933":["rustc 1.29.2 (17a9dc751 2018-10-05)\nbinary: rustc\ncommit-hash: 17a9dc7513b9fea883dc9505f09f97c63d1d601b\ncommit-date: 2018-10-05\nhost: x86_64-unknown-linux-gnu\nrelease: 1.29.2\nLLVM version: 7.0\n",""]}}
|
@ -0,0 +1 @@
|
||||
c9aea05b4f7bab6b
|
@ -0,0 +1 @@
|
||||
{"rustc":2049182171942789226,"features":"[]","target":8092603168892422263,"profile":7338771462028609488,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1541015098,863087767],".fingerprint/u03-4d5f92818f15e465/dep-bin-u03-4d5f92818f15e465"]}],"rustflags":[],"edition":"Edition2015"}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
d00b19fc5c9b0c78
|
@ -0,0 +1 @@
|
||||
{"rustc":2049182171942789226,"features":"[]","target":8092603168892422263,"profile":8925656243208791261,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1541015093,869731229],".fingerprint/u03-560dcfd44619ed7e/dep-bin-u03-560dcfd44619ed7e"]}],"rustflags":[],"edition":"Edition2015"}
|
Binary file not shown.
BIN
school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465
Executable file
BIN
school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465
Executable file
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465: src/main.rs
|
||||
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
@ -0,0 +1,5 @@
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-560dcfd44619ed7e.rmeta: src/main.rs
|
||||
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-560dcfd44619ed7e.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
school/intro-crypto/uebung/03/u03/target/debug/libu03.d
Normal file
1
school/intro-crypto/uebung/03/u03/target/debug/libu03.d
Normal file
@ -0,0 +1 @@
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/libu03.rmeta: /home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/src/main.rs
|
BIN
school/intro-crypto/uebung/03/u03/target/debug/u03
Executable file
BIN
school/intro-crypto/uebung/03/u03/target/debug/u03
Executable file
Binary file not shown.
1
school/intro-crypto/uebung/03/u03/target/debug/u03.d
Normal file
1
school/intro-crypto/uebung/03/u03/target/debug/u03.d
Normal file
@ -0,0 +1 @@
|
||||
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/u03: /home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/src/main.rs
|
Reference in New Issue
Block a user