Bacon cipher: Difference between revisions

Added 11l
m (→‎Raku: subsection for the original alternative algorithm "cheat")
(Added 11l)
Line 18:
# Show an example plaintext message encoded and then decoded here on this page.
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<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’,
‘p’ = ‘ABBBB’, ‘q’ = ‘BAAAA’, ‘r’ = ‘BAAAB’, ‘s’ = ‘BAABA’, ‘t’ = ‘BAABB’,
‘u’ = ‘BABAA’, ‘v’ = ‘BABAB’, ‘w’ = ‘BABBA’, ‘x’ = ‘BABBB’, ‘y’ = ‘BBAAA’,
‘z’ = ‘BBAAB’, ‘ ’ = ‘BBBAA’]
 
V rev_codes = Dict(codes.items(), (k, v) -> (v, k))
 
F encode(plaintext, message)
V et = ‘’
L(c) plaintext.lowercase()
et ‘’= I c C ‘a’..‘z’ {:codes[c]} E :codes[Char(‘ ’)]
 
V result = ‘’
V count = 0
L(c) message.lowercase()
I c C ‘a’..‘z’
result ‘’= I et[count] == ‘A’ {c} E c.uppercase()
count++
I count == et.len
L.break
E
result ‘’= c
R result
 
F decode(message)
V result = ‘’
V et = ‘’
L(c) message
I c C (‘A’..‘Z’, ‘a’..‘z’)
et ‘’= I c.is_lowercase() {‘A’} E ‘B’
L(i) (0 .< et.len - 4).step(5)
result ‘’= :rev_codes[et[i .< i + 5]]
R result
 
V plaintext = ‘the quick brown fox jumps over the lazy dog’
V message = ‘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.’
 
V ciphertext = encode(plaintext, message)
print(‘Cipher text →’)
print(ciphertext)
V decodedtext = decode(ciphertext)
print("\nHidden text →")
print(decodedtext)</lang>
 
{{out}}
<pre>
Cipher text →
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 An
 
Hidden text →
the quick brown fox jumps over the lazy dog
</pre>
 
=={{header|Ada}}==
1,481

edits