Bacon cipher: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1:
{{draft task}}
[[Category:Encryption]]
{{draft task}}
 
[[wp: Bacon's cipher| Bacon's cipher]] is a method of steganography created by Francis Bacon.
Line 22:
{{trans|Nim}}
 
<syntaxhighlight lang="11l">V 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’,
Line 85:
=={{header|Ada}}==
{{trans|Kotlin}}
<syntaxhighlight lang=Ada"ada">-- Bacon cipher
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 247:
Tested with Agena 2.9.5 Win32
{{Trans|ALGOL 68}}
<syntaxhighlight lang="agena"># Bacon cipher
 
# Bacon's letter codes but with distinct values for i & j and u & v and an extra for any non-letter
Line 353:
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68"># Bacon's letter codes but with distinct values for i & j and u & v and an extra for any non-letter #
[]STRING bacon codes = ( #a# "AAAAA", "AAAAB", "AAABA", "AAABB", "AABAA", "AABAB", "AABBA", "AABBB", "ABAAA"
, #j# "ABAAB", "ABABA", "ABABB", "ABBAA", "ABBAB", "ABBBA", "ABBBB", "BAAAA", "BAAAB"
Line 457:
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">Codes: #[
a: "AAAAA" b: "AAAAB" c: "AAABA" d: "AAABB" e: "AABAA"
f: "AABAB" g: "AABBA" h: "AABBB" i: "ABAAA" j: "ABAAB"
Line 533:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"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"
Line 574:
}
}</syntaxhighlight>
Examples:<syntaxhighlight lang=AutoHotkey"autohotkey">Message:= "
(join
bacon's cipher is a method of steganography created by francis bacon.
Line 601:
=={{header|BaCon}}==
A Bacon cipher in [[BaCon]]. Using unique identifiers 'aaaaa'-'bbaab' for a-z and, as other examples on this page, using 'bbbaa' (28) for the space character.
<syntaxhighlight lang="qbasic">msg$ = "the quick brown fox jumps over the lazy dog"
 
txt$ = "Bacon's cipher is a method of steganography created by Francis Bacon." \
Line 659:
=={{header|C}}==
{{trans|Kotlin}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Line 783:
=={{header|C sharp|C#}}==
{{trans|Java}}
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 866:
Bacon cipher implementation
 
<syntaxhighlight lang="cpp">
#include <iostream>
#include <algorithm>
Line 918:
These next 2 classes use the 0's & 1's generated by the 'Bacon encryption' to create different the outputs.
One could go wild here...
<syntaxhighlight lang="cpp">
class cipherI {
public:
Line 1,021:
2. Program
 
<syntaxhighlight lang="lisp">;; 22.06.16
 
(defconstant +codes+
Line 1,062:
3. Example
 
<syntaxhighlight lang="lisp">(defconstant +monologue+ (concatenate 'string
"I've known adventures, seen places you people will never see, I've been Offw"
"orld and back... frontiers ! I've stood on the back deck of a blinker bound "
Line 1,086:
 
=={{header|D}}==
<syntaxhighlight lang="d">import std.array;
import std.stdio;
import std.uni;
Line 1,193:
=={{header|Go}}==
{{trans|Kotlin}}
<syntaxhighlight lang="go">package main
 
import(
Line 1,290:
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class BaconCipher {
private static final Map<Character, String> codes
 
Line 1,389:
=={{header|Haskell}}==
 
<syntaxhighlight lang="haskell">-- Necessary imports
import Data.List (elemIndex, unfoldr)
import Data.Bool (bool)
Line 1,480:
Implementation:
 
<syntaxhighlight lang=J"j">alfa=: 'ABCDEFGHIKLMNOPQRSTUWXYZ'
beta=: 26{.(}.~i.&'A')a.
norm=: ([ -. -.)&alfa@(rplc&('JIVU'))@toupper
Line 1,493:
Example use:
 
<syntaxhighlight lang=J"j"> encrypt 'this is a test'
nWVkJAPkamEuUJIeTGKnUsTVRfAWWuNBIIHdEIcOAPuTBeXKQduQAdU
encrypt 'this is a test'
Line 1,503:
{{trans|Kotlin}}
{{works with|Java|9}}
<syntaxhighlight lang=Java"java">import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Line 1,595:
 
'''Preliminaries'''
<syntaxhighlight lang="jq">def is_upper: . >= "A" and . <= "Z";
 
def is_lower: . >= "a" and . <= "z";
Line 1,606:
</syntaxhighlight>
'''Bacon Cipher'''
<syntaxhighlight lang="jq">def Bacon:
{
"a" : "AAAAA", "b" : "AAAAB", "c" : "AAABA", "d" : "AAABB", "e" : "AABAA",
Line 1,672:
 
'''Module''':
<syntaxhighlight lang="julia">module BaconCipher
 
using Formatting, IterTools.chain
Line 1,740:
 
'''Main''':
<syntaxhighlight lang="julia">let msg = "Rosetta code Bacon cipher example secret phrase to encode in the capitalisation of peter pan"
enc = BaconCipher.encrypt(msg)
dec = BaconCipher.decrypt(enc)
Line 1,768:
=={{header|Kotlin}}==
The 'full' Bacon alphabet, which has separate letters for i, j, u and v, has been used in the following:
<syntaxhighlight lang="scala">object Bacon {
private val codes = mapOf(
'a' to "AAAAA", 'b' to "AAAAB", 'c' to "AAABA", 'd' to "AAABB", 'e' to "AABAA",
Line 1,844:
=={{header|Lua}}==
Based on C++ version
<syntaxhighlight lang=Lua"lua">
function Bacon( txt, secret, e )
local alpha = {}
Line 1,963:
 
=={{header|MiniScript}}==
<syntaxhighlight lang=MiniScript"miniscript">c = {}
c["a"] = "AAAAA"; c["b"] = "AAAAB"; c["c"] = "AAABA"; c["d"] = "AAABB"; c["e"] = "AABAA"; c["f"] = "AABAB";
c["g"] = "AABBA"; c["h"] = "AABBB"; c["i"] = "ABAAA"; c["j"] = "ABAAB"; c["k"] = "ABABA"; c["l"] = "ABABB";
Line 2,034:
=={{header|Nim}}==
{{trans|Kotlin}}
<syntaxhighlight lang=Nim"nim">import strutils, sugar, tables
 
const Codes = {'a': "AAAAA", 'b': "AAAAB", 'c': "AAABA", 'd': "AAABB", 'e': "AABAA",
Line 2,092:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use utf8;
Line 2,195:
half of/an obviously corrupt image file.
 
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">bits</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">mask</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bits</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
Line 2,280:
This deviates from the Bacon method as it encodes to different capitalisation of text rather than differences in font.
 
<syntaxhighlight lang="python">import string
 
sometext = """All children, except one, grow up. They soon know that they will grow
Line 2,369:
=={{header|Quackery}}==
 
<syntaxhighlight lang=Quackery"quackery"> [ dup upper swap lower != ] is ischar ( c --> b )
 
[ char a char z 1+ clamp
Line 2,444:
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">#lang racket
(require xml)
 
Line 2,511:
Not truly a Bacon Cipher as it doesn't encode using font variations. But fits with the spirit if not the exact definition.
{{works with|Rakudo|2015-11-20}}
<syntaxhighlight lang="raku" linesline>my $secret = q:to/END/;
This task is to implement a program for encryption and decryption
of plaintext using the simple alphabet of the Baconian cipher or
Line 2,592:
 
=== Bacon cipher solution ===
<syntaxhighlight lang="raku" linesline>my @abc = 'a' .. 'z';
my @symb = ' ', |@abc; # modified Baconian charset - space and full alphabet
# TODO original one with I=J U=V, nice for Latin
Line 2,654:
 
All alphabetic letters are handled as if they were in uppercase &nbsp; (i.e., lowercase letters are uppercased).
<syntaxhighlight lang="rexx">/*REXX program implements and demonstrates a (full) "Bacon" cipher (cypher).*/
parse arg plain /*obtain optional arguments from the CL*/
if plain='' then plain = "The quick brown fox jumped over the lazy dog."
Line 2,690:
:::* &nbsp; the &nbsp; ''bottom tee'' &nbsp; <big><big>┴</big></big> &nbsp; &nbsp; (sometimes known as the &nbsp; ''bottom junction'')
:::* &nbsp; the &nbsp; &nbsp; ''top tee'' &nbsp; &nbsp; &nbsp; <big><big>┬</big></big> &nbsp; &nbsp; (sometimes known as the &nbsp; ''top junction'')
<syntaxhighlight lang="rexx">/*REXX program implements and demonstrates a (full) "Bacon" cipher (cypher).*/
parse arg plain /*obtain optional arguments from the CL*/
if plain='' then plain = "The quick brown fox jumped over the lazy dog."
Line 2,723:
 
===uses upper/lower case===
<syntaxhighlight lang="rexx">/*REXX program implements and demonstrates a (full) "Bacon" cipher (cypher).*/
parse arg plain /*obtain optional arguments from the CL*/
if plain='' then plain = "The quick brown fox jumped over the lazy dog."
Line 2,757:
=={{header|Ruby}}==
{{trans|C#}}
<syntaxhighlight lang="ruby">CODES = {
'a' => "AAAAA", 'b' => "AAAAB", 'c' => "AAABA", 'd' => "AAABB", 'e' => "AABAA",
'f' => "AABAB", 'g' => "AABBA", 'h' => "AABBB", 'i' => "ABAAA", 'j' => "ABAAB",
Line 2,854:
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="scala">import scala.util.control.Breaks._
 
object BaconCipher {
Line 2,953:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<syntaxhighlight lang="vbnet">Imports System.Text
 
Module Module1
Line 3,051:
=={{header|Vlang}}==
{{trans|go}}
<syntaxhighlight lang="vlang">const codes = {
`a` : "AAAAA", `b` : "AAAAB", `c` : "AAABA", `d` : "AAABB", `e` : "AABAA",
`f` : "AABAB", `g` : "AABBA", `h` : "AABBB", `i` : "ABAAA", `j` : "ABAAB",
Line 3,141:
{{libheader|Wren-str}}
{{libheader|Wren-trait}}
<syntaxhighlight lang="ecmascript">import "/str" for Str, Char
import "/trait" for Stepped
 
Line 3,224:
=={{header|zkl}}==
{{trans|Python}}
<syntaxhighlight lang="zkl">class Bacon{
fcn init(_keyText){
var [const] keyText=_keyText.toLower(),
Line 3,254:
}
}</syntaxhighlight>
<syntaxhighlight lang="zkl">bacon:=Bacon(
#<<<
0'|All children, except one, grow up. They soon know that they will grow
10,333

edits