Skip to content

Instantly share code, notes, and snippets.

@originalsouth
Created March 22, 2020 17:37
Show Gist options
  • Save originalsouth/e25a3682bbc592a72ac875d456c6a0f3 to your computer and use it in GitHub Desktop.
Save originalsouth/e25a3682bbc592a72ac875d456c6a0f3 to your computer and use it in GitHub Desktop.
xor a potato
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