Well, you need a program to encrypt your doc, using a method that allow the decrypt. I made some test for fun with encrypters some time ago.

I'm sending a script that you can use in your docs. This use a key of numbers to move the bits to another position, bit by bit. The code was fully on Perl, can be slow in big files, since an encrypter normally is writed in C.

When you encrypt a doc NEVER lose the key number!!! Or you can decrypt it anymore! You can change some flags of the program, like the block size, and the key number will only work with the same flags used in the main encrypter.

This program was based in the idea (move bits) of ABC1 (A Bit Cypher program) published in IBM AlphaWorks. And I put the name James Bond, don't laughs! ;-P

This script is only for educational purpose, don't use it for malicious ways. And you can find better things on the Internet too...

"The creativity is the expression of the liberty".

To run just type: perl bond.pl
and fallow the promp, or use the -h flag for help.
SOURCE follows...
#!/usr/bin/perl ################################## # JAMES BOND ENCRYPTER/DECRYPTER # ################################## # By: Graciliano Monteiro Passos # # E-mail: gm@...spam_sux.... # # URL: www.virtuasites.com.br # # # # Created 3/22/2002 03:33H # # # # Copyright 2002 Virtua Sites. # # All rights reserved. # ################################## $|=1; ###################################################################### +######## # Based in the ABC1 (A Bit Cypher program) idea. Published in IBM alph +aWorks # ###################################################################### +######## # $file = '3.bmp' ; # $james_do = 'enc' ; #$data_key = '123' ; # $block_sz = 1024 ; #$data = 'data test' ; ######## # ARGS # ######## if ($#ARGV >= 0) { $james_do = $ARGV[0] || 'enc' ; $file = $ARGV[1] ; $data_key = $ARGV[2] || int(100000 + rand(999999)) ; $block_sz = $ARGV[3] || 1024 ; if ($james_do =~ /^-e/i ) { $james_do = 'enc' ;} elsif ($james_do =~ /^-d/i ) { $james_do = 'dec' ;} elsif ($james_do =~ /^-(p|h)/i ) { ;} else {$james_do = '-h' ;} } elsif ($data eq '') { $james_do = '-p' ;} ######## # HELP # ######## if ($james_do =~ /^-h/i) { print qq` _____________________________________________________________ JAMES BOND CRYTER 1.1 Based in the ABC1 (A Bit Cypher program) idea. Published in IBM alphaWorks _____________________________________________________________ Usage: -e %file %key %block_size >> Encrypt. -d %file %key %block_size >> Decrypt. Examples: 1> bond.pl -e data.txt 123abc 2> bond.pl -d data.txt.enc 123abc Detail: - The key can use letters. They ill be converted to the char number. - %block_size option (def: 1024) is the amount of bytes of each block to crypt. If you use a number not equal than 1024, you need to input the size in the decoder too! By: Graciliano M. P. URL: http://www.virtuasites.com Copyright 2002 Virtua Sites. All rights reserved. Have a nice day! :) _____________________________________________________________ `; exit ; } ########## # PROMPT # ########## if ($james_do =~ /^-p/i) { my ($prompt_do , $prompt_file , $prompt_key , $prompt_size, $prompt_ru +n); print qq` _____________________________________________________________ JAMES BOND CRYTER 1.1 `; $prompt_do = &prompt('encrypt/decrypt?','e',e,d); if ($prompt_do =~ /^d/i) { $prompt_do = 'dec' ;} else { $prompt_do = 'enc' ;} $prompt_file = &prompt('File',''); $prompt_file =~ s/\s//g ; if (! -e $prompt_file) { print " ** Can't find file $prompt_file\n" ; exit; } $prompt_key = &prompt('Key',int(100000 + rand(999999999))); $prompt_key =~ s/\s//g ; $prompt_size = &prompt('Block size','1024'); if ($prompt_size !~ /^\d+$/) { $prompt_size = 1024 ;} $prompt_run = &prompt('Run','y','y','n') ; print "_____________________________________________________________\n +\n" ; if ( $prompt_run =~ /^y/i ) { $file = $prompt_file ; $james_do = $prompt_do ; $data_key = $prompt_key ; $block_sz = $prompt_size ; } else { exit ;} } ########## # PROMPT # ########## sub prompt { my ( $msg , $def , @opt) = @_ ; my $prompt ; my $p_msg = " $msg " ; if ($#opt >= 0) { $p_msg .= "<". join (",", @opt) ; } if ($def ne '') { if ($#opt >= 0) { $p_msg .= ">" ;} $p_msg .= "<$def" ; } $p_msg .= "> " ; while($prompt eq '') { print $p_msg ; chop($prompt = <STDIN>); if ($prompt eq '' && $def ne '') { $prompt = ' ' ;} elsif ($#opt >= 0) { my $clean = 1 ; foreach my $opt_i ( @opt ) { if ($prompt =~ /^$opt_i$/i) { $prompt = $opt_i ; $clean = 0 ;} } if ($clean == 1) { $prompt = '' ;} } } if ($prompt =~ /^\s+$/ ) { $prompt = $def ;} print " <$prompt>\n\n" ; return( $prompt ) ; } ############# # DATA FILE # ############# $do_msg = 'data' ; if (-e $file && $file ne '') { $do_msg = $file ; open (LOG,$file) ; binmode(LOG); $data = join '' , <LOG> ; close (LOG) ; } ######## # INIT # ######## print "\n" ; if ($james_do =~ /^dec/i) { print " Decrypting... $do_msg\n " ; $james_data = &james_decrypt($data,$data_key) ; if ($file ne '') { if ($file =~ /\.enc\.(\w+)$/i ) { my $ext = $1 ; $file =~ s/\.enc\.\w+$//i ; $file_new = "$file.dec.$ext" ; } else { $file_new = "$file.dec" ;} } } elsif ($james_do =~ /^enc/i) { print " Encrypting... $do_msg\n " ; $james_data = &james_encrypt($data,$data_key); if ($file ne '') { my ($ext) = ( $file =~ /\.(\w+)$/g ); $file =~ s/\.$ext$// ; $file_new = "$file.enc.$ext" ; } } ########## # OUT UP # ########## if ($file_new ne '') { open (LOG,">$file_new") ; binmode(LOG); print LOG $james_data ; close (LOG) ; print "\n\n New data saved in file: $file_new\n" ; } else { print "\n New code -> $james_data\n" ; } print " KEY: $data_key\n" ; print " BLock size: $block_sz\n" ; ################# # JAMES_DECRYPT # ################# sub james_decrypt { my ( $data , $data_key ) = @_ ; my $data_new ; my $data_lng = length($data) ; $get_key_n = 0 ; for (my $i = 0 ; $i < $data_lng ;) { $p++; print "." ; if ($p =~ /\d0$/ ) { print "\n " ;} my $block = substr($data,$i,$block_sz) ; $i += $block_sz ; my $bits = get_bit($block); my $bits_lng = length($bits) - 1; my @bits = split("" , $bits) ; my @new_bits = ('') x ($bits_lng+1) ; my @dec_bits = ('') x ($bits_lng+1) ; my $c = -1 ; for (my $j = 0 ; $j <= $bits_lng ; $j++) { $c++; @bits[$j] = '' ; my $bt = substr($bits,$j,1) ; my $key_n = &get_key_n($data_key) ; my $pos = get_bit_pos($key_n,$j,$bits_lng) ; while(@new_bits[$pos] ne '') { $pos++ ; if ($pos > $bits_lng) { $pos = 0 ;} } @new_bits[$pos] = $bt ; @dec_bits[$j] = substr($bits,$pos,1) ; if ($c >= $bits_lng) { last ;} } my $new_bytes = &make_bytes( join ("", @dec_bits) ) ; $data_new .= $new_bytes ; } return( $data_new ) ; } ################# # JAMES_DECRYPT # ################# sub james_encrypt { my ( $data , $data_key ) = @_ ; my $data_new ; my $data_lng = length($data) ; $get_key_n = 0 ; for (my $i = 0 ; $i < $data_lng ;) { $p++; print "." ; if ($p =~ /\d0$/ ) { print "\n " ;} my $block = substr($data,$i,$block_sz) ; $i += $block_sz ; my $bits = get_bit($block); my $bits_lng = length($bits) - 1; my @bits = split("" , $bits) ; my @new_bits = ('') x ($bits_lng+1) ; my $c = -1 ; for (my $j = 0 ; $j <= $bits_lng ; $j++) { $c++; @bits[$j] = '' ; my $bt = substr($bits,$j,1) ; my $key_n = &get_key_n($data_key) ; my $pos = get_bit_pos($key_n,$j,$bits_lng) ; while(@new_bits[$pos] ne '') { $pos++ ; if ($pos > $bits_lng) { $pos = 0 ;} } @new_bits[$pos] = $bt ; if ($c >= $bits_lng) { last ;} } my $new_bytes = &make_bytes( join ("", @new_bits) ) ; $data_new .= $new_bytes ; } return( $data_new ) ; } ############### # GET_BIT_POS # ############### sub get_bit_pos { my ( $key_n , $pos , $size) = @_ ; my $new = $pos + ($key_n * $pos) ; #my $new = $pos / (1 + $key_n) ; while($new > $size) { $new -= $size ;} while($new < 0) { $new += $size ;} return( $new ) ; } ############# # GET_KEY_N # ############# sub get_key_n { my ($data_key) = @_ ; $get_key_n++ ; if ($get_key_n >= length($data_key)) { $get_key_n = 0 ;} my $n = substr($data_key,$get_key_n,1) ; if ($n =~ /\D/) { $n = unpack("C", $n) ;} return( $n ) ; } ########### # GET_BIT # ########### sub get_bit { my ( $s ) = @_ ; my $bit = unpack("b*", $s) ; return( $bit ) ; } ############## # MAKE_BYTES # ############## sub make_bytes { my ( $bits ) = @_ ; my $byte = pack("b*", $bits) ; return( $byte ) ; } ####### # END # ####### exit;

Edited ~Sun Jul 28 18:45:31 2002 (GMT), by footpad - Added <READMORE> tag, per Consideration.


In reply to Re: password protect. (with James Bond encrypter/decrypter source) by gmpassos
in thread password protect Word, PDF, etc documents by wellsayd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.