Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/bacon-cipher/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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. 3 secret = "rosetta code" 4 cover = "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." 5 bits = "".join(format(26 if c == " " else ord(c) - 97, "05b") for c in secret) 6 out, b = [], 0 7 for 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) 13 enc = "".join(out) 14 print(enc) 15 got = "".join("1" if c.isupper() else "0" for c in enc if c.isalpha())[:len(bits)] 16 print("".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)))