Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************
- * srm-dod v. 1.0 *
- * Description: Implementation of the DoD *
- * secure erase algorithm with a couple of *
- * modifications for extra obscurity *
- * Author: Michael Warren *
- * Date: January 8 & 17 2019 *
- *******************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- int main( int argc, char **argv ){
- FILE *fp;
- for( int i = 1; i < argc; i++ ){
- if( !(fp = fopen( argv[i], "r+" )) ){
- // Error handling section:
- char errorstring[strlen( argv[0] ) + strlen( argv[i] ) + 3];
- sprintf( errorstring, "%s: %s", argv[0], argv[i] );
- perror( errorstring );
- exit( errno );
- }
- // Determine file length:
- fseek( fp, 0, SEEK_END );
- long file_length = ftell( fp );
- rewind( fp );
- // Proceed with DoD algorithm:
- srand( time( NULL ) );
- char c = rand() % 256;
- for( int i = 0; i < file_length; i++ ){
- fputc( c, fp );
- }
- rewind( fp );
- c = ~c;
- for( int i = 0; i < file_length; i++ ){
- fputc( c, fp );
- }
- rewind( fp );
- for( int i = 0; i < file_length; i++ ){
- fputc( rand() % 256, fp );
- }
- rewind( fp );
- // Two extra zero passes to conceal the
- // fact that data was securely erased:
- for( int i = 0; i < file_length; i++ ){
- fputc( '\0', fp );
- }
- rewind( fp );
- for( int i = 0; i < file_length; i++ ){
- fputc( '\0', fp );
- }
- // Truncate:
- fclose( fp );
- fp = fopen( argv[i], "w" );
- fclose( fp );
- // Change filename and delete:
- char newname[TMP_MAX];
- for( int i = 0; i < TMP_MAX; i++ ){
- newname[i] = rand() % 26 + 'A';
- }
- if( rename( argv[i], newname ) ){
- printf( "%s: Error renaming file %s\n", argv[0], argv[i] );
- printf( "Error code: %d\n", errno );
- exit( errno );
- }
- remove( newname );
- fclose( fp );
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment