Bacon cipher: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,664: | Line 1,664: | ||
{{out}} |
{{out}} |
||
<pre>cOMpuTErs aRE eVErywHErE. THErE aRE ThE OBVIOuS OnEs, Like YOUR SMarT PHoNe or GaMe sYSteM. therE ARE lEsS obvIoUs ones, lIKE iN YouR mICRowAVE or youR BeDsidE CLock. AnD tHeN ThERe ARE the rEAlLY inVIsibLE oNEs, liKE ThE 50 or SO SMAll COmpuTERs in YOUR Car.All tHESe cO |
<pre>cOMpuTErs aRE eVErywHErE. THErE aRE ThE OBVIOuS OnEs, Like YOUR SMarT PHoNe or GaMe sYSteM. therE ARE lEsS obvIoUs ones, lIKE iN YouR mICRowAVE or youR BeDsidE CLock. AnD tHeN ThERe ARE the rEAlLY inVIsibLE oNEs, liKE ThE 50 or SO SMAll COmpuTERs in YOUR Car.All tHESe cO |
||
the quick brown fox jumps over the lazy dog</pre> |
|||
=={{header|Nim}}== |
|||
{{trans|Kotlin}} |
|||
<lang Nim>import strutils, sugar, tables |
|||
const 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"}.toTable |
|||
let RevCodes = collect(newTable, for k, v in Codes.pairs: {v: k}) |
|||
proc encode(plaintext, message: string): string = |
|||
var et: string |
|||
for c in plaintext.toLowerAscii: |
|||
et.add if c in 'a'..'z': Codes[c] else: Codes[' '] |
|||
var count = 0 |
|||
for c in message.toLowerAscii: |
|||
if c in 'a'..'z': |
|||
result.add if et[count] == 'A': c else: c.toUpperAscii |
|||
inc count |
|||
if count == et.len: break |
|||
else: |
|||
result.add c |
|||
proc decode(message: string): string = |
|||
var et: string |
|||
for c in message: |
|||
if c.isAlphaAscii: |
|||
et.add if c.isLowerAscii: 'A' else: 'B' |
|||
for i in countup(0, et.high - 4, 5): |
|||
result.add RevCodes[et[i..(i+4)]] |
|||
when isMainModule: |
|||
const |
|||
PlainText = "the quick brown fox jumps over the lazy dog" |
|||
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." |
|||
let cipherText = PlainText.encode(Message) |
|||
echo "Cipher text →\n", cipherText |
|||
let decodedText = cipherText.decode() |
|||
echo "\nHidden text →\n", 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> |
the quick brown fox jumps over the lazy dog</pre> |
||