-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grigory Bakunov
committed
Aug 23, 2012
1 parent
b5b2934
commit 9cf2421
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf-8 | ||
import sys, itertools | ||
|
||
replacers = { | ||
"ru": ( | ||
('а', 'с', 'о', 'р', 'е', 'х', 'у', 'А', 'В', 'Е', 'С', 'К', 'М', 'О', 'Р', 'Х'), | ||
('a', 'c', 'o', 'p', 'e', 'x', 'y', 'A', 'B', 'E', 'C', 'K', 'M', 'O', 'P', 'X'), | ||
), | ||
} | ||
|
||
def get_code_iter(code): | ||
return itertools.cycle([int(x) for x in ''.join([ str(bin(ord(ch)))[2:] for ch in code ])]) | ||
|
||
|
||
def steganoText(text, code, lang='ru'): | ||
code_i = get_code_iter(code) | ||
fin = [] | ||
repl = replacers[lang] | ||
rw = { l[0]:l[1] for l in zip(repl[0] + repl[1], repl[1]+repl[0])} | ||
for x in text: | ||
t = (rw[x] if next(code_i) else x) if x in rw.keys() else x | ||
if t != x: | ||
print (t, x) | ||
else: | ||
print (x) | ||
return ''.join(fin) | ||
|
||
def main(args): | ||
code = ' '.join(args) if args else 'bobuk' | ||
block = sys.stdin.read() | ||
sys.stdout.write(steganoText(block, code)) | ||
|
||
if __name__ == '__main__': | ||
main(sys.argv[1:]) |