string-encryption-met-wachtwoord

Gesponsorde koppelingen

PHP script bestanden

  1. string-encryption-met-wachtwoord

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
//functie die een string omzet in binair.
function str2bin($str) {
    $array = str_split($str,1);
    $bin = '';
    foreach($array as $chr) {
        $bin.=decbin_fix(ord($chr));
    }

    return $bin;
}


//functie die een binaire string omzet in een string.
function bin2str($bin) {
    $array = str_split($bin,8);
    $str = '';
    foreach($array as $chr) {
        $str.=chr(bindec($chr));
    }

    return $str;
}


//functie die een getal omzet in een binair getal en deze links aanvult met het opgegeven aantal 0-en.
function decbin_fix($int,$length = 8) {
    return str_pad(decbin($int),$length,'0',STR_PAD_LEFT);
}

function
livc_hex2bin($hex) {
    $hex = str_split($hex,1);
    $bin = '';
    foreach($hex as $h) {
        $bin.=str_pad(base_convert($h,16,2),4,'0',STR_PAD_LEFT);
    }

    return $bin;
}

function
bin_encrypt($bin,$password) {
    if($password == '') {
        return $bin;
    }

    $password = livc_hex2bin(md5($password));
    $bin = str_split($bin,1);
    $password = str_split($password,1);
    $pcp = 0;//password cursor position
    $bcp = 0;//binairy cursor position
    while($bcp<count($bin)) {
        if($pcp<count($password)) {
            $pcp ++;
        }
else {
            $pcp = 0;
        }

        if($password[$pcp]=='1' && $bin[$bcp]=='0') {
            $bin[$bcp] = '1';
        }
elseif($password[$pcp]=='1' && $bin[$bcp]=='1') {
            $bin[$bcp] = '0';
        }

        $bcp ++;
    }

    $bin = array_reduce($bin,'merge');
    return $bin;
}

function
merge($a,$b) {
    return $a.$b;
}

function
str_encrypt($str,$password) {
    return bin2str(bin_encrypt(str2bin($str),$password));
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Zelf Extracting Installer</title>
<style type="text/css">
textarea {
    width:400px;
    height:200px;
    font-size:16px;
}
input {
    width:200px;
}
* {
    margin:0px;
}
</style>
</head>
<body>
<center>

    <form method="post">
        <h2>Input:</h2>
        <textarea name="input"><?php echo stripslashes($_POST['input']);?></textarea>
        <h2>Password:</h2>
        <input type="text" name="password" value="<?php echo stripslashes($_POST['password']);?>"/>
        <br/>
        <input type="submit" style="width:400px;height:40px;font-size:20px;" value="APPLY ENCRYPTION OR DECRYPTION"/>
    </form>
    <?php if(isSet($_POST['input'])) { ?>
    <h2>Output:</h2>
    <h3 style="color:red;">Warning: output may contain characters that can NOT be copy-pasted.</h3>
    <h3 style="color:red;">"Output reversion" is used to check if the output is correct.</h3>
    <h3>If you want copy-paste-able outputs, you should convert the output to HEX or BIN.</h3>
    <h3>Use livc_bin2hex(str2bin($string)) to convert a string to HEX.</h3>
    <h3>Use bin2str(livc_hex2bin($string)); to convert it back to a STRING.</h3>
    <textarea><?php echo str_encrypt(stripslashes($_POST['input']),stripslashes($_POST['password']));?></textarea>
    
    <h2>Output reversed:</h2>
    <h3>to check if encryption is succes</h3>
    <textarea><?php echo str_encrypt(str_encrypt(stripslashes($_POST['input']),stripslashes($_POST['password'])),stripslashes($_POST['password']));?></textarea>
    
    <h2>Decryption of Encrypted string: <?php if(str_encrypt(str_encrypt(stripslashes($_POST['input']),stripslashes($_POST['password'])),stripslashes($_POST['password']))===stripslashes($_POST['input'])){echo '<span style="color:green;">SUCCES</span>';}else {echo '<span style="color:red;">FAIL</span>';}?></h2>
    <?php } ?>

</center>
</body>
</html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.