Below is a little routine I wrote to encrypt and decrypt a file.
This script is meant for encrypting text files and sending them privately through e-mail as an attachment.
Note: The author makes no claims about whether this encryption technique can be broken. It would not be easy.
Here is what you need to use this program.
- Mac or other computer that can run a perl script from the command line
- very basic knowledge of how to create and edit a file from the command line
Step One , cut and paste the code below into a file in your (MAC) computer
You’ll also need this same program on any receiving computer where you expect to be able to decrypt the file.
Create the text file you want to encrypt. I used the following and saved it off.
Dear Mom,
I really hate my boss he is a real jerk, and I even think he reads my private out going e-mails by intercepting them. So I am using this encryption device to send you this message.
Dave the Paranoid
Here is how the process to encrypt and decrypt looks from my command line
I saved off my text to a file aptly named “file” into my working directory
I saved off the perl code below and put it into an executable file called “test”
I then ran the encryption program.
MacBook-Air:~ root# ./test ./file ./n encrypt “you live in a tree”
./test is the perl program
./file is the input file with the text I want to encrypt
./n is the output file for the encrypted message, I could send this text file as an attachment to an e-mail , and the receiving users would need the same perl program and “key” to encrypt
encrypt is the directive to the program to encrypt, the other option is decrypt to reverse the process
“you live in a tree”
is my key. You can make it any text string of characters you want as long as you include it in quotes, the more random and the longer, the harder it will be for somebody to break
I then reversed the process to decrypt the file ./n and store the results in file “x”
MacBook-Air:~ root# ./test ./n x decrypt “you live in a tree”
the cat command below prints the contents of the newly decrypted file x
MacBook-Air:~ root# cat x
Dear Mom,
I really hate my boss he is a real jerk, and I even think he reads my private out going e-mails, by intercepting them. So I am using this encryption device to send you this message.
Dave the Paranoid
MacBook-Air:~ root#
————–code starts below this line do not include this line————–
#! /usr/bin/perl
# encryption tool ARG1 input file name, ARG2 key,ARG3 output file name
$key=$ARGV[3];
if ( ! defined $ARGV[3] )
{
print ” encode infile outfile [encrypt|descrypt] key\n”;
exit 1;
}
open (INFILE, $ARGV[0] ) || die “open whitelist file $ARGV[0]”;
open( OUTFILE, ‘>’, $ARGV[1]) or die “Could not open file ‘$ARGV[1]”;
while ($string= )
{
chomp($string);
if ($ARGV[2] eq “encrypt”)
{
my @chars = split(“”, $string);
my @keychars=split(“”,$key);
$charsize= @chars;
$keysize=@keychars;
$n=0;
for ($i=0; $i < $charsize; $i++) { $num1=ord($chars[$i]); $num2 = ord ($keychars[$n]); $chars[$i] = ord($chars[$i]) + $num2; print OUTFILE “$chars[$i],”; $n=$n+1; if ( $n > ( $keysize -1) )
{
$n=0;
}
}
my ($str) = join “”,@chars;
print OUTFILE “\n”;
}
if ( $ARGV[2] eq “decrypt”)
{
#decrypt
$n=0;
my @chars = split(“,”, $string);
my @keychars=split(“”,$key);
$charsize= @chars;
$keysize=@keychars;
for ($i=0; $i < $charsize; $i++) { $num1=$chars[$i]; $num2=ord($keychars[$n]); $num3 = ($num1 – $num2); $chars[$i] = chr($num3); $n=$n+1; if ( $n > ( $keysize -1) )
{
$n=0;
}
}
my ($str) = join “”,@chars;
print OUTFILE “$str\n” ;
} # end decrypt
} # end while input line
May 11, 2017 at 7:06 PM
[…] How to Create and Send an Encrypted File With No NSA Backdoor […]