Bacon cipher: Difference between revisions
Content added Content deleted
Alpha bravo (talk | contribs) (Added AutoHotkey) |
|||
Line 531: | Line 531: | ||
Message: |
Message: |
||
the quick brown fox jumps over the lazy dog</pre> |
the quick brown fox jumps over the lazy dog</pre> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>Bacon_Cipher(message, plaintext:=""){ |
|||
codes := {"a":"AAAAA", "b":"AAAAB", "c":"AAABA", "d":"AAABB", "e":"AABAA" |
|||
, "f":"AABAB", "g":"AABBA", "h":"AABBB", "i":"ABAAA", "j":"ABAAB" |
|||
, "k":"ABABA", "l":"ABABB", "m":"ABBAA", "n":"ABBAB", "o":"ABBBA" |
|||
, "p":"ABBBB", "q":"BAAAA", "r":"BAAAB", "s":"BAABA", "t":"BAABB" |
|||
, "u":"BABAA", "v":"BABAB", "w":"BABBA", "x":"BABBB", "y":"BBAAA" |
|||
, "z":"BBAAB", " ":"BBBAA"} |
|||
if (plaintext<>"") { |
|||
for i, letter in StrSplit(plaintext) |
|||
code .= codes[letter] |
|||
x := StrSplit(code) |
|||
for i, letter in StrSplit(message) |
|||
if (Asc(letter) >= 97 and Asc(letter) <= 122) |
|||
if !(l := x.RemoveAt(1)) |
|||
break |
|||
else if (l = "A") |
|||
cipher .= letter |
|||
else |
|||
cipher .= Chr(Asc(letter) - 32) |
|||
else |
|||
cipher .= letter |
|||
return cipher |
|||
} else { |
|||
Keys := [] |
|||
for l, c in codes |
|||
Keys[c] := l |
|||
for i, letter in StrSplit(message) |
|||
if (Asc(letter) >= 97 and Asc(letter) <= 122) |
|||
pattern .= "A" |
|||
else if (Asc(letter) >= 65 and Asc(letter) <= 90) |
|||
pattern .= "B" |
|||
while StrLen(pattern) |
|||
str .= Keys[SubStr(pattern, 1, 5)] |
|||
, pattern := SubStr(pattern, 6) |
|||
return str |
|||
} |
|||
}</lang> |
|||
Examples:<lang AutoHotkey>Message:= " |
|||
(join |
|||
bacon's cipher is a method of steganography created by francis bacon. |
|||
this task is to implement a program for encryption and decryption of |
|||
plaintext using the simple alphabet of the baconian cipher or some |
|||
other kind of representation of this alphabet (make anything signify anything). |
|||
the baconian alphabet may optionally be extended to encode all lower |
|||
case characters individually and/or adding a few punctuation characters |
|||
such as the space. |
|||
)" |
|||
plaintext := "the quick brown fox jumps over the lazy dog" |
|||
MsgBox, 262144, ,% "plain text = " plaintext |
|||
. "`n`nencoded = `n" (cipher := Bacon_Cipher(message, plaintext)) |
|||
. "`n`ndecoded = " recoveredText := Bacon_Cipher(cipher)</lang> |
|||
{{out}} |
|||
<pre>plain text = the quick brown fox jumps over the lazy dog |
|||
encoded = |
|||
BacON's cIPHer Is a METhoD of stEgAnogRaphy crEatEd By FRAncis baCOn.thIs TASk Is TO imPLeMENT a proGrAm FOR eNcRYPTIOn anD deCRyPtioN OfplAINTExt UsING the SIMpLe AlPhaBet Of thE BAConIan CIphER Or sOmeOTHer kInD Of reprESenTATion OF This alPHaBET (makE An |
|||
decoded = the quick brown fox jumps over the lazy dog |
|||
</pre> |
|||
=={{header|BaCon}}== |
=={{header|BaCon}}== |