Skip to content

Instantly share code, notes, and snippets.

@skoji
Created September 28, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skoji/de158cfe008e242057a791773982b64e to your computer and use it in GitHub Desktop.
Save skoji/de158cfe008e242057a791773982b64e to your computer and use it in GitHub Desktop.
EPUB3 OCF unobfuscate test code (not sure it is correct or not)
// unobfuscate test code in OCF https://www.w3.org/publishing/epub3/epub-ocf.html#obfus-algorithm
// [dependencies]
// sha-1 = "0.9.8"
use sha1::{Digest, Sha1};
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
const KEY: &[u8] = b"key string";
const SRC: &str = "resource_to_decrypt.bin";
const DEST: &str = "resource_decrypted.bin";
fn main() {
let mut hasher = Sha1::new();
hasher.update(KEY);
let r = hasher.finalize();
println!("{:?}", r);
let path = Path::new(SRC);
let opath = Path::new(DEST);
let mut file = File::open(&path).unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
for i in 0..52 {
for (index, v) in r.iter().enumerate() {
buffer[i * r.len() + index] = buffer[i * r.len() + index] ^ v;
}
}
let mut outfile = File::create(opath).unwrap();
outfile.write_all(&buffer).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment