Created
March 22, 2020 17:37
-
-
Save originalsouth/e25a3682bbc592a72ac875d456c6a0f3 to your computer and use it in GitHub Desktop.
xor a potato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::prelude::*; | |
use std::fs::File; | |
fn main() { | |
let mut f = File::open("./potato").unwrap(); | |
let mut inbuffer = Vec::new(); | |
// read the whole file | |
f.read_to_end(&mut inbuffer); | |
for i in 0..inbuffer.len() { | |
inbuffer[i] ^= 82; | |
} | |
let mut outbuffer = File::create("out").unwrap(); | |
write_data(&mut outbuffer, &inbuffer); | |
} | |
fn write_data(buffer: &mut File, data: &[u8]) | |
{ | |
let mut pos = 0; | |
while pos < data.len() { | |
let bytes_written = buffer.write(&data[pos..]).unwrap(); | |
pos += bytes_written; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment