Jump to content

Very simple 2 way encryption?


aximbigfan

Recommended Posts

Hi,

 

I'm codign a log viewer, and I finished up most of the core stuff, and now an doign the extra stuff.

 

One thing is that th password for the configuration system is stored in plain text, in a .ini file. The app does checked to make sure that permission to the file is denied (from the web browser, no preventing it from explorer).

 

Still though, I would really like just a basic 2 way encryption system. Can anyone show me how this is done? Nothing complex, just shift the position of the letters/numbers over like 5 spots or something.

 

It will eventually need to be a bit more complex, but if someone can just show me an outline of how to do it, I'm sure I could pick it up pretty fast. I just haven't done much with this kind of thing...

 

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/91368-very-simple-2-way-encryption/
Share on other sites

md5 is one-way

 

An easy 2-way is str_rot13()

 

<?php
$str = 'abcde';

$encrypt = str_rot13($str);

echo $encrypt . '<br/>';           // nopqr

$orig = str_rot13($encrypt);

echo $orig;                        // abcde

?>

A slightly more complex 2-way method is to use xor bitwise operator

 

<?php

        function simpleEncrypt($str, $key)
        {
            $k = strlen ($str) ;
            $encrypt = '';
            for($i=0;$i<$k;$i++) {
                
                 $encrypt .= ($str[$i]^($key));      // Xor each character with the key char
            }
            return $encrypt;
        }


$str = 'abcde';
$key = ch r(128);

$enc = simpleEncrypt($str, $key);

echo $enc, '<br/>';

$orig = simpleEncrypt($enc, $key);

echo $orig;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.