Writing a file shredder in python or ruby?
In the effort to learn python and/or ruby, I was wondering how 开发者_JAVA百科a file shredder would be implemented? I would like it to take in a file as an argument and then employ an algorithm to make that file unrecoverable. Would possibly add the support for multiple files or even whole directories later.
Just as a warning, shredders generally will have varying levels of success on modern systems, thanks to journals, copy-on-write file systems, wear leveling (flash), and other techniques used in modern system. Might wanna check out wikipedia on some of the pitfalls.
In short, you'd need to be able to write directly on top of the currently existing data. There's a few different patterns of varying levels of security, but often if you overwrite the file about 25 times with random data (rounding up to the next block size) the file should be completely unrecoverable (at least that copy of the data). There are other techniques that can securely overwrite it in less passes (3 passes, random, ones, then zeros also works decently well).
Since this is a learning exercise and not a professional attempt to secure data. How about this: 1. Discover the length of the file. 2. Write 0's to the same length of the file. 3. Save the file. 4. Delete the file.
Then make another program that tries to recover the file.
But yes, if looking to make something professional and not just an exercise, look into kitsune's answer.
精彩评论