Home » PHP scripts » Standard Baconian decoder

Bacon’s cipher or the Baconian cipher is a method of steganography (a method of hiding a secret message as opposed to just a cipher) devised by Francis Bacon in 1605. A message is concealed in the presentation of text, rather than its content.

To encode a message, each letter of the plaintext is replaced by a group of five of the letters ‘A’ or ‘B’. This replacement is a binary encoding and is done according to the alphabet of the Baconian cipher (from the Latin Alphabet).

You can find out more about Baconian cipher on Wikipedia.

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
<?php
function baconian_decode($string,$method)
{
    $string = preg_replace('/[^A-Za-z\-]/', '', $string);
    $string2 = "";
    for($i=0;$i<strlen($string);$i++)
    {
        $a = $string[$i];
        $chr = ord($a);
        if($chr > 64 && $chr < 91)
        {
            $string2 .= "B";
        }else{
            $string2 .= "A";
        }
        $j = $i+1;
        if($j % 5 == 0)
        {
            $string2 .= " ";
        }
    }
    $ijuv = array("AAAAA"=>"a",
    "AAAAB"=>"b",
    "AAABA"=>"c",
    "AAABB"=>"d",
    "AABAA"=>"e",
    "AABAB"=>"f",
    "AABBA"=>"g",
    "AABBB"=>"h",
    "ABAAA"=>"i",
    "ABAAB"=>"k",
    "ABABA"=>"l",
    "ABABB"=>"m",
    "ABBAA"=>"n",
    "ABBAB"=>"o",
    "ABBBA"=>"p",
    "ABBBB"=>"q",
    "BAAAA"=>"r",
    "BAAAB"=>"s",
    "BAABA"=>"t",
    "BAABB"=>"u",
    "BABAA"=>"w",
    "BABAB"=>"x",
    "BABBA"=>"y",
    "BABBB"=>"z");
    $normal = array("AAAAA"=>"a",
    "AAAAB"=>"b",
    "AAABA"=>"c",
    "AAABB"=>"d",
    "AABAA"=>"e",
    "AABAB"=>"f",
    "AABBA"=>"g",
    "AABBB"=>"h",
    "ABAAA"=>"i",
    "ABAAB"=>"j",
    "ABABA"=>"k",
    "ABABB"=>"l",
    "ABBAA"=>"m",
    "ABBAB"=>"n",
    "ABBBA"=>"o",
    "ABBBB"=>"p",
    "BAAAA"=>"q",
    "BAAAB"=>"r",
    "BAABA"=>"s",
    "BAABB"=>"t",
    "BABAA"=>"u",
    "BABAB"=>"v",
    "BABBA"=>"w",
    "BABBB"=>"x",
    "BBAAA"=>"y",
    "BBAAB"=>"z");
    $string2 = explode(" ",$string2);
    $s = "";
    if($method == 1)
    {
        foreach($string2 as $string)
        {
            $s .= $ijuv[$string];
        }
    }else{
        foreach($string2 as $string)
        {
            $s .= $normal[$string];
        }
    }
    return $s;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*