Dreamweaver::encode_password()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
namespace Redbox\Dreamweaver;
3
4
class Dreamweaver
5
{
6
    /**
7
     * Encode a given password
8
     *
9
     * @param string $string
10
     * @return string
11
     */
12 4
    public static function encode_password($string = '') {
13 4
        $items = array();
14 4
        $len = strlen($string);
15 4
        for ($i = 0; $i < $len; $i++)
16
        {
17 4
            $items[] = dechex( ord($string[$i]) + $i ) ;
18 4
        }
19 4
        return strtoupper(implode('', $items));
20
    }
21
22
    /**
23
     * Decode a given password.
24
     *
25
     * @param string $encoded
26
     * @return string
27
     */
28 4
    public static function decode_password($encoded = '') {
29 4
        $literals = explode(' ', wordwrap($encoded, 2, ' ', 2));
30 4
        $length   = count($literals);
31 4
        $pass     = '';
32 4
33 4
        for ($i = 0; $i < $length; $i++) {
34
            $pass .= chr(hexdec($literals[$i]) - $i);
35 4
        }
36
        return $pass;
37
    }
38
}