Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

encrypt() and decrypt() 1

Status
Not open for further replies.

BenRussell

Programmer
Mar 12, 2001
243
US
I was told by a security expert that there is a Perl module that will give you access to the encrypt() and decrypt() functions (like PHP has built-in). Does anyone know what module this is? - Ben Russell
- President of Intracor Technologies (
 
if u want readl security (up to 2048b)
try :
but be aware those requires other modules that requires others mudule that .....

u can still do a home made one like this simple example below (this is very basic ...im sure u know why)

Code:
$the_message = "blablabla";
$the_key = "otherbla";

my $test_encode = &string2hex(&RC4($the_message,$the_key));
my $test_decode = &RC4(&hex2string($test_encode),$the_key);

print $test_encode . "\n\n" . $test_decode;

sub RC4 {
 my($message,$key) = @_;
 my($RC4);
 my(@asciiary);
 my(@keyary);
 my($index,$jump,$temp,$y,$t,$x,$keylen);
 $keylen = length($key);
 for ($index = 0; $index <= 255; $index++) {
  $keyary[$index] = ord(substr($key, ($index%$keylen) + 1, 1));
 }
 for ($index = 0; $index <= 255; $index++) {$asciiary[$index] = $index;}
 $jump = 0;
 for ($index = 0; $index <= 255; $index++) {
  $jump = ($jump + $asciiary[$index] + $keyary[$index])%256;
  $temp = $asciiary[$index];
  $asciiary[$index] = $asciiary[$jump];
  $asciiary[$jump] = $temp;
 }
 $index = 0;
 $jump = 0;
 for ($x = 0; $x < length($message); $x++) {
  $index = ($index + 1)%256;
  $jump = ($jump + $asciiary[$index])%256;
  $t = ($asciiary[$index] + $asciiary[$jump])%256;
  $temp = $asciiary[$index];
  $asciiary[$index] = $asciiary[$jump];
  $asciiary[$jump] = $temp;
  $y = $asciiary[$t];
  $RC4 .= chr(ord(substr($message, $x, 1))^$y);
 }
 return($RC4);
}

sub string2hex {
 my($instring) = @_;
 my($retval,$strlen,$posx,$tval,$h1,$h2);
 my(@hexvals) = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
 $strlen = length($instring);
 for ($posx = 0; $posx < $strlen; $posx++) {
  $tval = ord(substr($instring,$posx,1));
  $h1 = int($tval/16);
  $h2 = int($tval - ($h1*16));
  $retval .= $hexvals[$h1] . $hexvals[$h2];
 }
 return($retval);
}

sub hex2string {
 my($instring) = @_;
 my($retval,$strlen,$posx);
 $strlen = length($instring);
 for ($posx = 0; $posx < $strlen; $posx=$posx+2) {
  $retval .= chr(hex(substr($instring,$posx,2)));
 }
 return($retval);
}
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Well, I really need the encrypt and decrypt functions, because it has to be a reversable encryption (therefore I cant use crypt). Any idea what module can do this? - Ben Russell
- President of Intracor Technologies (
 
There are several modules that are available depending on what algorithm you want to use. Most modules are named Crypt::* where the last part is the name of the algorithm (such as DES, RSA, or Blowfish). Check them out at CPAN.


scroll down a bit to see the Crypt::* modules.

jaa
 
Which one (if thers more than one you can tell me that too) would you suggest I use if I need one that can be decrypted also? I know MD5 is one of the strongest, but it cant be decrypted. - Ben Russell
- President of Intracor Technologies (
 
Hi Ben,

I strongly suggest you use this module:


This is what I use everytime and it's pretty simple to set up. All you do is make a directory called &quot;My&quot; and add the &quot;crypt.pm&quot;.


There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Bear in mind that the suggested module is not very secure at all. It works by simply xor'ing the messsage with a passkey that you supply. Therefore its security depends on the length of the passkey you provide. If security isn't really a concern then that's fine, but if it is I strongly suggest that you do not use it.

jaa
 
I would suggest Crypt::IDEA, Crypt::Blowfish, or perhaps Crypt::Solitaire.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top