interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / bacon-cipher / oracle.py

16 lines · 790 bytes Raw Blame History
1# Independent reference for "Bacon cipher" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3secret = "rosetta code"
4cover = "bacon's cipher is a method of steganography devised by francis bacon. a message is concealed in the presentation of text rather than its content."
5bits = "".join(format(26 if c == " " else ord(c) - 97, "05b") for c in secret)
6out, b = [], 0
7for c in cover:
8 if "a" <= c <= "z" and b < len(bits):
9 if bits[b] == "1":
10 c = c.upper()
11 b += 1
12 out.append(c)
13enc = "".join(out)
14print(enc)
15got = "".join("1" if c.isupper() else "0" for c in enc if c.isalpha())[:len(bits)]
16print("".join(" " if int(got[i:i + 5], 2) == 26 else chr(97 + int(got[i:i + 5], 2)) for i in range(0, len(got), 5)))